library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
library(reshape2)
library(dunn.test) #dunn test
library(FSA) #alternative dunn test
## ## FSA v0.8.20. See citation('FSA') if used in publication.
## ## Run fishR() for related website and fishR('IFAR') for related book.
library(EMT) #exact multinomial test
library(boot)
library(readr)
## TO DO:
# Remove nearest from all the plots
## Fill in first visits, make simply neither OR nearest, not both: make only sound v smell include nearest? Make data include that.
## Remove nearest??
## do GLMM
## revise colors of plots: blue and green?
#remove trachops?
## Get basic plots out
## Make powerpoint with that story
## Update plots with new data
## Recolor plots into powerpoint theme
## Ask Rachel for nicer vectored versions of the plots she sent
## Add first visits if time
## Then could LATER compare the total visits accross the three trial types (make trial order a random variable)
LocVSound <- read.csv("~/GitHub/Sensory_learning/Sensory_learning_1/LocVSound_08.06.18.csv")
SoundVSmell <- read_csv("~/GitHub/Sensory_learning/Sensory_learning_1/SoundVSmell_08.08.18.csv")
## Parsed with column specification:
## cols(
## .default = col_integer(),
## Bat.ID = col_character(),
## Scorer = col_character(),
## Date = col_character(),
## Time = col_time(format = ""),
## Species = col_character(),
## Test = col_character(),
## Rewarded_sound = col_character(),
## Rewarded_smell = col_character(),
## first_hover = col_character(),
## first_land = col_character(),
## first_visit = col_character(),
## pct_visits_sound = col_double(),
## pct_visits_smell = col_double(),
## pct_visits_neither = col_double(),
## pct_visits_nearest = col_double()
## )
## See spec(...) for full column specifications.
LocVSmell <- read_csv("~/GitHub/Sensory_learning/Sensory_learning_1/LocVSmell_08.06.18.csv")
## Parsed with column specification:
## cols(
## .default = col_integer(),
## Bat.ID = col_character(),
## Scorer = col_character(),
## Date = col_character(),
## Time = col_character(),
## Species = col_character(),
## Treatment = col_character(),
## Rewarded_loc = col_number(),
## Rewarded_smell = col_character(),
## first_hover = col_character(),
## first_land = col_character(),
## first_visit = col_character(),
## pct_visits_loc = col_double(),
## pct_visits_smell = col_double(),
## pct_visits_neither = col_double(),
## pct_visits_nearest = col_character()
## )
## See spec(...) for full column specifications.
colnames(LocVSmell)
## [1] "Bat.ID" "Scorer" "Date"
## [4] "Time" "Species" "Treatment"
## [7] "Rewarded_loc" "Rewarded_smell" "first_hover"
## [10] "first_land" "first_visit" "lands_loc"
## [13] "hovers_loc" "visits_loc" "lands_smell"
## [16] "hovers_smell" "visits_smell" "lands_neither"
## [19] "hovers_neither" "visits_neither" "visits_nearest"
## [22] "visits_sassafras" "visits_almond" "visits_cinnamon"
## [25] "visits_anise" "total_lands" "total_hovers"
## [28] "total_visits" "pct_visits_loc" "pct_visits_smell"
## [31] "pct_visits_neither" "pct_visits_nearest"
#remove columns "visits_nearest" "pct_visits_nearest"
first_choices <- read_csv("~/GitHub/Sensory_learning/Sensory_learning_1/first_response_08.08.08.csv")
## Parsed with column specification:
## cols(
## `Bat ID` = col_character(),
## Scorer = col_character(),
## Date = col_character(),
## Time = col_character(),
## Species = col_character(),
## Test = col_character(),
## Rewarded_1 = col_character(),
## Rewarded_2 = col_character(),
## first_hover = col_character(),
## first_land = col_character(),
## first_visit = col_character()
## )
first_choices <- subset(first_choices, first_choices$Species != "T") # no Trachops
first_choices$first_visit <- factor(first_choices$first_visit, levels = c("location", "sound", "smell", "neither"))
#######This removes the nearest columns##########
drops <- c("vists_nearest","pct_visits_nearest")
LocVSound <- LocVSound[ , !(names(LocVSound) %in% drops)]
LocVSmell <- LocVSmell[ , !(names(LocVSmell) %in% drops)]
SoundVSmell <- SoundVSmell[ , !(names(SoundVSmell) %in% drops)]
########################################
## COLOR PALETTE SETTINGS ##
Lo <- "#468902" # A blue color,
Art <-"#133954" # A green color
Mypal <- c(Lo, Art)
head(LocVSound)
## Bat.ID Scorer Date Time Species Test Rewarded_loc
## 1 A-C095 unknown 4/1/17 1 AJ LocVSound 4,2
## 2 D-C0B6 unknown 4/2/17 23:45 AJ LocVSound 4,2
## 3 K-C091 May 4/30/17 21:47 AJ LocVSound 3,3
## 4 B-Butt Dylan 7/1/17 21:37 L LocVSound 3,1
## 5 C-Newbie Dylan 7/1/17 19:12 L LocVSound 3,2
## 6 Cracker_Jacks May 5/28/17 <NA> T LocVSound 4,2
## Rewarded_sound first_hover first_land first_visit lands_loc hovers_loc
## 1 epsilon location location location 1 10
## 2 epsilon neither location neither 5 1
## 3 feta location <NA> location 0 13
## 4 feta location location location 0 5
## 5 feta location location location 15 7
## 6 sassafrass location location location 4 0
## visits_loc lands_sound hovers_sound visits_sound lands_neither
## 1 11 0 0 0 0
## 2 6 0 0 0 0
## 3 13 0 1 1 0
## 4 5 0 0 0 0
## 5 22 0 0 0 0
## 6 4 0 0 0 1
## hovers_neither visits_neither lands_nearest hovers_nearest
## 1 1 1 0 1
## 2 5 5 NA <NA>
## 3 5 5 0 0
## 4 0 0 0 1
## 5 0 0 NA <NA>
## 6 0 1 1 0
## visits_nearest lands_alpha hovers_alpha visits_alpha lands_beta
## 1 1 NA NA NA 0
## 2 NA NA NA NA 5
## 3 0 0 5 5 NA
## 4 1 0 5 5 NA
## 5 NA 0 0 0 15
## 6 1 4 0 4 NA
## hovers_beta visits_beta lands_feta hovers_feta visits_feta lands_epsilon
## 1 1 1 1 10 11 0
## 2 1 6 0 5 5 0
## 3 NA NA 0 1 1 0
## 4 NA NA 0 1 1 0
## 5 7 22 0 0 0 0
## 6 NA NA 1 0 1 0
## hovers_epsilon visits_epsilon total_lands total_hovers total_visits
## 1 0 0 1 11 12
## 2 0 0 5 6 11
## 3 13 13 0 19 19
## 4 0 0 0 5 6
## 5 0 0 15 7 22
## 6 0 0 5 0 5
## pct_visits_loc pct_visits_sound pct_visits_neither
## 1 0.9166667 0.00000000 0.08333333
## 2 0.5454545 0.00000000 0.45454545
## 3 0.6842105 0.05263158 0.26315789
## 4 0.8333333 0.00000000 0.00000000
## 5 1.0000000 0.00000000 0.00000000
## 6 0.8000000 0.00000000 0.20000000
## make a subset with only lophos and AJs, remove Trachops as factor level
LocVSound_AJ_L= subset(LocVSound, LocVSound$Species != "T")
##View(LocVSound_AJ_L)
LocVSound_AJ_L$Species<- factor(LocVSound_AJ_L$Species)
#levels(LocVSound_AJ_L$Species)
SUMMARIZING AVERAGE proportion of visits to each cue
# summarize average visits per species using dplyr
# summarize number
# seperate out the species
#look at histograms of responses
# run kruskal wallace? Anova with percents?
# Make graphs: percentage choices for each species
#
Avg_pct_visits<-LocVSound_AJ_L %>% group_by(Species) %>%
summarise(avg_sound = mean(pct_visits_sound, na.rm=TRUE)*100, avg_loc= mean(pct_visits_loc, na.rm=TRUE)* 100 ,avg_neither = mean(pct_visits_neither, na.rm=TRUE)*100 )
Avg_pct_visits
## # A tibble: 2 x 4
## Species avg_sound avg_loc avg_neither
## <fct> <dbl> <dbl> <dbl>
## 1 AJ 16.1 59.3 24.6
## 2 L 9.60 79.2 9.38
SUMMARIZING AVERAGE NUMBER of of visits overall, per species
### Can also look at the absolute number of times that a given species visits or lands on a platform (total visits)
## summary of the mean of the total visits / species mean of the total lands / species, mean of the total hovers/ species
Avg_visits_spc<-LocVSound_AJ_L %>% group_by(Species) %>%
summarise(avg_vis = mean(total_visits, na.rm=TRUE), sd_vis = sd(total_visits), avg_lands = mean(total_lands, na.rm=TRUE), sd_lands = sd(total_lands), avg_hovers = mean(total_hovers, na.rm=TRUE), sd_hovers = sd(total_hovers) )
Avg_visits_spc
## # A tibble: 2 x 7
## Species avg_vis sd_vis avg_lands sd_lands avg_hovers sd_hovers
## <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 AJ 19.8 12.7 1.83 3.35 17.9 11.4
## 2 L 23.3 19.6 9.89 9.70 13.3 14.8
class(Avg_visits_spc)
## [1] "tbl_df" "tbl" "data.frame"
#seems like lophos may go the the platforms more on average. At a glance:
t.test(LocVSound_AJ_L$total_visits[LocVSound_AJ_L$Species =="AJ"], LocVSound_AJ_L$total_visits[LocVSound_AJ_L$Species =="L"])
##
## Welch Two Sample t-test
##
## data: LocVSound_AJ_L$total_visits[LocVSound_AJ_L$Species == "AJ"] and LocVSound_AJ_L$total_visits[LocVSound_AJ_L$Species == "L"]
## t = -0.47754, df = 12.896, p-value = 0.641
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -19.80733 12.64066
## sample estimates:
## mean of x mean of y
## 19.75000 23.33333
# At least not obviously there isn't a difference in visits
#But do they land more? At a glance:
t.test(LocVSound_AJ_L$total_lands[LocVSound_AJ_L$Species =="AJ"], LocVSound_AJ_L$total_lands[LocVSound_AJ_L$Species =="L"])
##
## Welch Two Sample t-test
##
## data: LocVSound_AJ_L$total_lands[LocVSound_AJ_L$Species == "AJ"] and LocVSound_AJ_L$total_lands[LocVSound_AJ_L$Species == "L"]
## t = -2.3865, df = 9.4426, p-value = 0.03956
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -15.6371410 -0.4739701
## sample estimates:
## mean of x mean of y
## 1.833333 9.888889
#Ya, Lophostoma are more likely to actually land than AJs
## basically assessing normality
hist(LocVSound_AJ_L$pct_visits_sound[LocVSound_AJ_L$Species=="L"], breaks=6)
#not particularly normal
head(LocVSound_AJ_L)
## Bat.ID Scorer Date Time Species Test Rewarded_loc
## 1 A-C095 unknown 4/1/17 1 AJ LocVSound 4,2
## 2 D-C0B6 unknown 4/2/17 23:45 AJ LocVSound 4,2
## 3 K-C091 May 4/30/17 21:47 AJ LocVSound 3,3
## 4 B-Butt Dylan 7/1/17 21:37 L LocVSound 3,1
## 5 C-Newbie Dylan 7/1/17 19:12 L LocVSound 3,2
## 7 B-C09E Dylan 4/5/17 19:41 AJ LocVSound 4,2
## Rewarded_sound first_hover first_land first_visit lands_loc hovers_loc
## 1 epsilon location location location 1 10
## 2 epsilon neither location neither 5 1
## 3 feta location <NA> location 0 13
## 4 feta location location location 0 5
## 5 feta location location location 15 7
## 7 epsilon NA <NA> <NA> 0 0
## visits_loc lands_sound hovers_sound visits_sound lands_neither
## 1 11 0 0 0 0
## 2 6 0 0 0 0
## 3 13 0 1 1 0
## 4 5 0 0 0 0
## 5 22 0 0 0 0
## 7 0 0 0 0 0
## hovers_neither visits_neither lands_nearest hovers_nearest
## 1 1 1 0 1
## 2 5 5 NA <NA>
## 3 5 5 0 0
## 4 0 0 0 1
## 5 0 0 NA <NA>
## 7 0 0 0 0
## visits_nearest lands_alpha hovers_alpha visits_alpha lands_beta
## 1 1 NA NA NA 0
## 2 NA NA NA NA 5
## 3 0 0 5 5 NA
## 4 1 0 5 5 NA
## 5 NA 0 0 0 15
## 7 0 0 0 0 0
## hovers_beta visits_beta lands_feta hovers_feta visits_feta lands_epsilon
## 1 1 1 1 10 11 0
## 2 1 6 0 5 5 0
## 3 NA NA 0 1 1 0
## 4 NA NA 0 1 1 0
## 5 7 22 0 0 0 0
## 7 0 0 0 0 0 0
## hovers_epsilon visits_epsilon total_lands total_hovers total_visits
## 1 0 0 1 11 12
## 2 0 0 5 6 11
## 3 13 13 0 19 19
## 4 0 0 0 5 6
## 5 0 0 15 7 22
## 7 0 0 0 0 0
## pct_visits_loc pct_visits_sound pct_visits_neither
## 1 0.9166667 0.00000000 0.08333333
## 2 0.5454545 0.00000000 0.45454545
## 3 0.6842105 0.05263158 0.26315789
## 4 0.8333333 0.00000000 0.00000000
## 5 1.0000000 0.00000000 0.00000000
## 7 NA NA NA
Do AJs go to one platform more than another? Do Lophostoma go to any platforms more than one another? Which? Is there a difference between AJs and lophostoma? (anova? )
# pull out just the relevent columns:
LocVSound_AJ_L_pcts<- LocVSound_AJ_L[ , c("Bat.ID", "Species", "pct_visits_loc", "pct_visits_sound", "pct_visits_neither")]
head(LocVSound_AJ_L_pcts)
## Bat.ID Species pct_visits_loc pct_visits_sound pct_visits_neither
## 1 A-C095 AJ 0.9166667 0.00000000 0.08333333
## 2 D-C0B6 AJ 0.5454545 0.00000000 0.45454545
## 3 K-C091 AJ 0.6842105 0.05263158 0.26315789
## 4 B-Butt L 0.8333333 0.00000000 0.00000000
## 5 C-Newbie L 1.0000000 0.00000000 0.00000000
## 7 B-C09E AJ NA NA NA
## Alternatively could just put all the rows I don't want melted into "id" in the following fuction.
colnames(LocVSound_AJ_L_pcts)
## [1] "Bat.ID" "Species" "pct_visits_loc"
## [4] "pct_visits_sound" "pct_visits_neither"
mLocVSound <- melt(LocVSound_AJ_L_pcts, id=c("Bat.ID","Species"))
hist(mLocVSound$value)
head(mLocVSound)
## Bat.ID Species variable value
## 1 A-C095 AJ pct_visits_loc 0.9166667
## 2 D-C0B6 AJ pct_visits_loc 0.5454545
## 3 K-C091 AJ pct_visits_loc 0.6842105
## 4 B-Butt L pct_visits_loc 0.8333333
## 5 C-Newbie L pct_visits_loc 1.0000000
## 6 B-C09E AJ pct_visits_loc NA
#rm(mLocVSound )
# pull out just the relevent columns:
LocVSound_AJ_L_cnts<- LocVSound_AJ_L[ , c("Bat.ID", "Species", "visits_loc", "visits_sound", "visits_neither")]
head(LocVSound_AJ_L_cnts)
## Bat.ID Species visits_loc visits_sound visits_neither
## 1 A-C095 AJ 11 0 1
## 2 D-C0B6 AJ 6 0 5
## 3 K-C091 AJ 13 1 5
## 4 B-Butt L 5 0 0
## 5 C-Newbie L 22 0 0
## 7 B-C09E AJ 0 0 0
## Alternatively could just put all the rows I don't want melted into "id" in the following fuction, which would save the rest of the data
colnames(LocVSound_AJ_L_cnts)
## [1] "Bat.ID" "Species" "visits_loc" "visits_sound"
## [5] "visits_neither"
mLocVSound_cnts <- melt(LocVSound_AJ_L_cnts, id=c("Bat.ID","Species"))
head(mLocVSound_cnts)
## Bat.ID Species variable value
## 1 A-C095 AJ visits_loc 11
## 2 D-C0B6 AJ visits_loc 6
## 3 K-C091 AJ visits_loc 13
## 4 B-Butt L visits_loc 5
## 5 C-Newbie L visits_loc 22
## 6 B-C09E AJ visits_loc 0
## convenient also to just add this count value to mLocvSound
visits_counts<-mLocVSound_cnts$value
mLocVSound <-cbind(mLocVSound, visits_counts)
" Did the bats fly to the three platforms the same amount? (W/in species): independent variables: 1: cue (3 levels) dependent variables: 1: percent visits by bat, not independent AJS #### Kruskal-wallace: AJ
LvS_AJ_k.test<- kruskal.test(value ~ variable, data =mLocVSound[mLocVSound$Species =="AJ", ] )
LvS_AJ_k.test
##
## Kruskal-Wallis rank sum test
##
## data: value by variable
## Kruskal-Wallis chi-squared = 16.419, df = 2, p-value = 0.000272
Significant difference, bats did not fly to the three platforms equally, so post-hocs
LvS_L_k.test<- kruskal.test(value ~ variable, data =mLocVSound[mLocVSound$Species =="L", ] )
LvS_L_k.test
##
## Kruskal-Wallis rank sum test
##
## data: value by variable
## Kruskal-Wallis chi-squared = 17.809, df = 2, p-value = 0.0001358
Significant difference, so post-hocs
“Which platforms did the bats fly to more, which were different?”
LvS_AJ_wilhox = pairwise.wilcox.test(mLocVSound[mLocVSound$Species =="AJ", ]$value, mLocVSound[mLocVSound$Species =="AJ", ]$variable, p.adjust.method=p.adjust.methods)
## Warning in wilcox.test.default(xi, xj, paired = paired, ...): cannot
## compute exact p-value with ties
## Warning in wilcox.test.default(xi, xj, paired = paired, ...): cannot
## compute exact p-value with ties
LvS_AJ_wilhox
##
## Pairwise comparisons using Wilcoxon rank sum test
##
## data: mLocVSound[mLocVSound$Species == "AJ", ]$value and mLocVSound[mLocVSound$Species == "AJ", ]$variable
##
## pct_visits_loc pct_visits_sound
## pct_visits_sound 0.0015 -
## pct_visits_neither 0.0015 0.1473
##
## P value adjustment method: holm
AJs visited the location significantly more than they visited the sound or the control platform, there was no detectable difference between percent visits to sound or neither
LvS_L_wilhox = pairwise.wilcox.test(mLocVSound[mLocVSound$Species =="L", ]$value, mLocVSound[mLocVSound$Species =="L", ]$variable, p.adjust.method=p.adjust.methods)
## Warning in wilcox.test.default(xi, xj, paired = paired, ...): cannot
## compute exact p-value with ties
## Warning in wilcox.test.default(xi, xj, paired = paired, ...): cannot
## compute exact p-value with ties
## Warning in wilcox.test.default(xi, xj, paired = paired, ...): cannot
## compute exact p-value with ties
LvS_L_wilhox
##
## Pairwise comparisons using Wilcoxon rank sum test
##
## data: mLocVSound[mLocVSound$Species == "L", ]$value and mLocVSound[mLocVSound$Species == "L", ]$variable
##
## pct_visits_loc pct_visits_sound
## pct_visits_sound 0.0011 -
## pct_visits_neither 0.0011 1.0000
##
## P value adjustment method: holm
Same with Lophostoma, they were significantly more likely to visit location, over sound or the control, no difference between those.
LvS_AJ_dunn<-dunnTest(mLocVSound[mLocVSound$Species =="AJ", ]$value, mLocVSound[mLocVSound$Species =="AJ", ]$variable, method="holm", kw=TRUE)
## Warning: Some rows deleted from 'x' and 'g' because missing data.
LvS_AJ_dunn
## Dunn (1964) Kruskal-Wallis multiple comparison
## p-values adjusted with the Holm method.
## Comparison Z P.unadj P.adj
## 1 pct_visits_loc - pct_visits_neither 2.824830 4.730567e-03 0.0094611334
## 2 pct_visits_loc - pct_visits_sound 3.928280 8.555571e-05 0.0002566671
## 3 pct_visits_neither - pct_visits_sound 1.103449 2.698321e-01 0.2698320863
LvS_L_dunn<-dunnTest(mLocVSound[mLocVSound$Species =="L", ]$value, mLocVSound[mLocVSound$Species =="L", ]$variable, method="holm", kw=TRUE)
LvS_L_dunn
## Dunn (1964) Kruskal-Wallis multiple comparison
## p-values adjusted with the Holm method.
## Comparison Z P.unadj
## 1 pct_visits_loc - pct_visits_neither 3.63174896 0.0002815069
## 2 pct_visits_loc - pct_visits_sound 3.67714582 0.0002358582
## 3 pct_visits_neither - pct_visits_sound 0.04539686 0.9637909822
## P.adj
## 1 0.0005630138
## 2 0.0007075747
## 3 0.9637909822
Independent variables: species (categorical, 2 levels) cue (categorical, 2 levels) Dependent variables: # visits, proportion visits
No good non-parametric option for a 2 way anova.
#proportion data
boxplot(value ~ variable* Species, data = mLocVSound) #box width of largest looks more than 2x larger than that of smaller
bartlett.test( value ~ interaction(variable, Species), data = mLocVSound) #Bartlett test shows variances arn't so different
##
## Bartlett test of homogeneity of variances
##
## data: value by interaction(variable, Species)
## Bartlett's K-squared = 4.0889, df = 5, p-value = 0.5367
# proportions don't have normal variance
# Count data also does not have homogenaity of variances boxplot(value ~ variable* Species, data = mLocVSound_cnts)
bartlett.test( value ~ interaction(variable, Species), data = mLocVSound_cnts)
##
## Bartlett test of homogeneity of variances
##
## data: value by interaction(variable, Species)
## Bartlett's K-squared = 34.198, df = 5, p-value = 2.175e-06
# does not have homogenaity of variance
# Proportion data transformations #
mLocVSound$value_sqrt<- (sqrt(mLocVSound$value)) #sqrt transformation
mLocVSound$value_cub = sign(mLocVSound$value) * abs(mLocVSound$value)^(1/3) #cubed transformation
mLocVSound$value_log<- (log(mLocVSound$value))#log transformation- too strong
# Count data transformations #
mLocVSound_cnts$value_sqrt<- (sqrt(mLocVSound_cnts$value)) #sqrt transformation
mLocVSound_cnts$value_cub = sign(mLocVSound_cnts$value) * abs(mLocVSound_cnts$value)^(1/3) #cubed transformation
mLocVSound_cnts$value_log<- (log(mLocVSound_cnts$value))#log transformation- too strong
# Proportion data boxplots #
boxplot(value ~ variable* Species, data = mLocVSound) #original
#ok
boxplot(value_sqrt ~ variable* Species, data = mLocVSound) #sqrt
##pretty good
boxplot(value_cub ~ variable* Species, data = mLocVSound) #cub, less good
boxplot(value_log ~ variable* Species, data = mLocVSound) # too strong
## Warning in bplt(at[i], wid = width[i], stats = z$stats[, i], out =
## z$out[z$group == : Outlier (-Inf) in boxplot 3 is not drawn
#Count data boxplots #
boxplot(value ~ variable* Species, data = mLocVSound_cnts) #unequal variance
boxplot(value_sqrt ~ variable* Species, data = mLocVSound_cnts) #sqrt, pretty good
boxplot(value_cub ~ variable* Species, data = mLocVSound_cnts) #cub, pretty good
boxplot(value_log ~ variable* Species, data = mLocVSound_cnts) # too strong
## Warning in bplt(at[i], wid = width[i], stats = z$stats[, i], out =
## z$out[z$group == : Outlier (-Inf) in boxplot 1 is not drawn
## Warning in bplt(at[i], wid = width[i], stats = z$stats[, i], out =
## z$out[z$group == : Outlier (-Inf) in boxplot 3 is not drawn
bartlett.test( value_log ~ interaction(variable, Species), data = mLocVSound_cnts)
##
## Bartlett test of homogeneity of variances
##
## data: value_log by interaction(variable, Species)
## Bartlett's K-squared = NaN, df = 5, p-value = NA
## This actually seems to have fixed the homogenaity of variances problem
#normality? Less important, ANOVAs are robust against this violation
#proportions:
hist(mLocVSound$value[mLocVSound$Species=="L"], breaks=6)
hist(mLocVSound$value_sqrt[mLocVSound$Species=="L"], breaks=6)
#hist(mLocVSound$value_cub[mLocVSound$Species=="L"], breaks=6)
#counts:
hist(mLocVSound_cnts$value[mLocVSound_cnts$Species=="L"], breaks=6)
hist(mLocVSound_cnts$value_sqrt[mLocVSound_cnts$Species=="L"], breaks=6)
hist(mLocVSound_cnts$value_cub[mLocVSound_cnts$Species=="L"], breaks=6)
hist(mLocVSound_cnts$value_log[mLocVSound_cnts$Species=="L"], breaks=8)
str(mLocVSound_cnts)
## 'data.frame': 63 obs. of 7 variables:
## $ Bat.ID : Factor w/ 22 levels "A-C095","B-Butt",..: 1 9 17 2 7 3 19 4 15 21 ...
## $ Species : Factor w/ 2 levels "AJ","L": 1 1 1 2 2 1 2 2 1 2 ...
## $ variable : Factor w/ 3 levels "visits_loc","visits_sound",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ value : int 11 6 13 5 22 0 23 9 16 43 ...
## $ value_sqrt: num 3.32 2.45 3.61 2.24 4.69 ...
## $ value_cub : num 2.22 1.82 2.35 1.71 2.8 ...
## $ value_log : num 2.4 1.79 2.56 1.61 3.09 ...
table(mLocVSound_cnts$value)
##
## 0 1 2 3 4 5 6 7 8 9 10 11 12 13 15 16 18 21 22 23 31 33 43
## 16 8 2 1 1 5 5 3 3 4 1 2 2 1 1 1 1 1 1 1 1 1 1
sum(mLocVSound_cnts$value == 0)
## [1] 16
##View(mLocVSound_cnts)
Probably best to use count data with ANOVA, proportions may be real, so use the cube transformation ## Anova with transformed count data, type 2
library(car)
## Loading required package: carData
##
## Attaching package: 'car'
## The following object is masked from 'package:boot':
##
## logit
## The following object is masked from 'package:FSA':
##
## bootCase
## The following object is masked from 'package:dplyr':
##
## recode
anova_LvS <- aov(value_cub ~ Species*variable, data=mLocVSound_cnts)
anova_LvS
## Call:
## aov(formula = value_cub ~ Species * variable, data = mLocVSound_cnts)
##
## Terms:
## Species variable Species:variable Residuals
## Sum of Squares 0.79690 17.12332 3.29159 41.39585
## Deg. of Freedom 1 2 2 57
##
## Residual standard error: 0.852199
## Estimated effects may be unbalanced
Anova(anova_LvS, type = 2)
## Anova Table (Type II tests)
##
## Response: value_cub
## Sum Sq Df F value Pr(>F)
## Species 0.797 1 1.0973 0.2993
## variable 17.123 2 11.7890 5.191e-05 ***
## Species:variable 3.292 2 2.2662 0.1130
## Residuals 41.396 57
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
No obvious effect of species, only the effect of the treatments. I know this isn’t a really nice way to do this, but not sure how else to do it.
## Could get the mean proportion of visits to cues from each of the species. bootstrap the mean proportion, then compare the 95% confidence intervals for each mean
############CODE FROM BASTI#################################################
#X will be the vector of proportions or rates or counts for one treatment in a species. It will calculate 5000 means based on re-sampling your data and then calculate the confidence intervals from that mean-distribution.
#The function spits out a vector of three values, the lower CI, mean, and upper CI.
#This is the function used for it:
#https://www.rdocumentation.org/packages/boot/versions/1.3-20/topics/boot.ci
###########################################################################
#mean function
mean.w <- function(x,w) sum(x*w) # calculates a mean
#bootstrapped confidence intervals function
boot_ci <- function(x){
mean <- mean(x)
low <- boot.ci(boot(data=x, statistic=mean.w, R=5000, stype="w"), type="basic")$basic[1,4]
high <- boot.ci(boot(data=x, statistic=mean.w, R=5000, stype="w"), type="basic")$basic[1,5]
c(low,mean,high)} # bootstraps the confidence intervals
## get rid of NAs in data using complete.cases
mLocVSound_na<-mLocVSound[complete.cases(mLocVSound[ ,4:6]), ] #removes NA rows in value columns 4:6, this might now make sense if I change the number of columns
#New database without NAs in the selected columns
LocVSound_AJ_L_na <- LocVSound_AJ_L[complete.cases(LocVSound_AJ_L[ ,c("visits_loc", "visits_sound", "visits_neither", "pct_visits_loc", "pct_visits_sound", "pct_visits_neither")]), ]
#The CI's for loc v Sound, percentages
set.seed(1)
LvS_pct_CI <- do.call(data.frame,aggregate(value ~ Species + variable , boot_ci, data = mLocVSound_na)) #This applies the bootstrap accross species and treatment variables, and do.call puts the data.frame in the right format
colnames(LvS_pct_CI) <- c("Species", "variable", "low", "mean", "high")
# The CIs for Loc V Sound, counts
LvS_count_CI <- do.call(data.frame, aggregate(visits_counts ~ Species + variable , boot_ci, data = mLocVSound_na))
LvS_count_CI
## Species variable visits_counts.V1 visits_counts.V2
## 1 AJ pct_visits_loc 8.0909091 10.909091
## 2 L pct_visits_loc 9.4472313 18.777778
## 3 AJ pct_visits_sound 1.4545455 4.545455
## 4 L pct_visits_sound 0.2222222 2.666667
## 5 AJ pct_visits_neither 3.0909091 6.090909
## 6 L pct_visits_neither 0.1111111 1.777778
## visits_counts.V3
## 1 13.363636
## 2 28.111111
## 3 7.181818
## 4 5.000000
## 5 8.818182
## 6 3.111111
colnames(LvS_count_CI) <- c("Species", "variable", "low", "mean", "high")
#LvS_pct_CI$Species <- factor(LvS_pct_CI$Species, levels=c("AJ", "L"), labels = c("A. jamaicensis", "L. silvicolum")) #need to do this for plot legends to say full name
#LvS_count_CI$Species <- factor(LvS_count_CI$Species, levels=c("AJ", "L"), labels = c("A. jamaicensis", "L. silvicolum"))
pd = position_dodge(0.5) # move bars .05 to the left and right
#proportion plot
LvS_pct_CI_p <- ggplot(data = LvS_pct_CI, aes(x=variable, y = mean, colour = Species))
LvS_pct_CI_p <- LvS_pct_CI_p + geom_errorbar(aes(ymin = low, ymax = high), width =.1, position = pd)
LvS_pct_CI_p <- LvS_pct_CI_p + geom_point( position = pd, shape=18, size = 3)
LvS_pct_CI_p <- LvS_pct_CI_p + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
LvS_pct_CI_p <- LvS_pct_CI_p + scale_x_discrete(labels=c("pct_visits_loc" = "Location", "pct_visits_sound" = "Sound",
"pct_visits_neither" = "Neither")) # Relabelling X axis
LvS_pct_CI_p <- LvS_pct_CI_p + xlab("Cues")
LvS_pct_CI_p <- LvS_pct_CI_p + ylab("Mean proportion of visits")
LvS_pct_CI_p <- LvS_pct_CI_p + scale_color_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
LvS_pct_CI_p
#ggsave("LvS_pct_CI_p.png" )
#count plot
LvS_count_CI_p <- ggplot(data = LvS_count_CI, aes(x=variable, y = mean, colour = Species))
LvS_count_CI_p <- LvS_count_CI_p + geom_errorbar(aes(ymin = low, ymax = high), width =.1, position = pd)
LvS_count_CI_p <- LvS_count_CI_p + geom_point( position = pd, shape=18, size = 3)
LvS_count_CI_p <- LvS_count_CI_p + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
LvS_count_CI_p <- LvS_count_CI_p + scale_x_discrete(labels=c("pct_visits_loc" = "Location", "pct_visits_sound" = "Sound",
"pct_visits_neither" = "Neither")) # Relabelling X axis
LvS_count_CI_p <- LvS_count_CI_p + xlab("Cues")
LvS_count_CI_p <- LvS_count_CI_p + ylab("Mean number of visits")
LvS_count_CI_p <- LvS_count_CI_p + scale_color_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
LvS_count_CI_p
#ggsave("LvS_count_CI_p.png" )
LocVSound_bar <- ggplot(data =mLocVSound, aes(x = variable, y = value))
LocVSound_bar <- LocVSound_bar + geom_boxplot(aes(fill=Species))
LocVSound_bar <- LocVSound_bar + geom_point(position=position_dodge(width=0.75), aes(group=Species), alpha = 1/4) #makes points semi-transparent
LocVSound_bar <- LocVSound_bar + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
LocVSound_bar <- LocVSound_bar + xlab("Cues")
LocVSound_bar <- LocVSound_bar + ylab("Proportion of total visits")
LocVSound_bar <- LocVSound_bar + scale_x_discrete(labels=c("pct_visits_loc" = "Location", "pct_visits_sound" = "Sound",
"pct_visits_neither" = "Neither" )) # Relabelling X axis
#LocVSound_bar <- LocVSound_bar + scale_fill_discrete(labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
LocVSound_bar <- LocVSound_bar + scale_fill_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
LocVSound_bar
## Warning: Removed 3 rows containing non-finite values (stat_boxplot).
## Warning: Removed 3 rows containing missing values (geom_point).
#ggsave("LocVSound_pcts.png")
LocVSound_bar_cnts <- ggplot(data =mLocVSound_cnts, aes(x = variable, y = value))
LocVSound_bar_cnts <- LocVSound_bar_cnts + geom_boxplot(aes(fill=Species))
LocVSound_bar_cnts <- LocVSound_bar_cnts + geom_point(position=position_dodge(width=0.75), aes(group=Species), alpha = 1/4) #makes points semi-transparent
LocVSound_bar_cnts <- LocVSound_bar_cnts + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
LocVSound_bar_cnts <- LocVSound_bar_cnts + xlab("Cues")
LocVSound_bar_cnts <- LocVSound_bar_cnts + ylab("Number of visits")
LocVSound_bar_cnts <- LocVSound_bar_cnts + scale_x_discrete(labels=c("visits_loc" = "Location", "visits_sound" = "Sound",
"visits_neither" = "Neither" )) # Relabelling X axis
LocVSound_bar_cnts <- LocVSound_bar_cnts + scale_fill_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
LocVSound_bar_cnts
#ggsave("LocVSound_cnts.png")
head(first_choices)
## # A tibble: 6 x 11
## `Bat ID` Scorer Date Time Species Test Rewarded_1 Rewarded_2
## <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
## 1 A-C095 unkno… 4/1/… 1 AJ LocV… 4,2 epsilon
## 2 D-C0B6 unkno… 4/2/… 23:45 AJ LocV… 4,2 epsilon
## 3 K-C091 May 4/30… 21:47 AJ LocV… 3,3 feta
## 4 B-Butt Dylan 7/1/… 21:37 L LocV… 3,1 feta
## 5 C-Newbie Dylan 7/1/… 19:12 L LocV… 3,2 feta
## 6 B-C09E Dylan 4/5/… 19:41 AJ LocV… 4,2 epsilon
## # ... with 3 more variables: first_hover <chr>, first_land <chr>,
## # first_visit <fct>
fc_LocVSound<- first_choices[first_choices$Test=="LocVSound" & first_choices$first_visit!= "nearest",] #pulling out Loc V Sound and cutting nearests
head(fc_LocVSound)
## # A tibble: 6 x 11
## `Bat ID` Scorer Date Time Species Test Rewarded_1 Rewarded_2
## <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
## 1 A-C095 unkno… 4/1/… 1 AJ LocV… 4,2 epsilon
## 2 D-C0B6 unkno… 4/2/… 23:45 AJ LocV… 4,2 epsilon
## 3 K-C091 May 4/30… 21:47 AJ LocV… 3,3 feta
## 4 B-Butt Dylan 7/1/… 21:37 L LocV… 3,1 feta
## 5 C-Newbie Dylan 7/1/… 19:12 L LocV… 3,2 feta
## 6 <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## # ... with 3 more variables: first_hover <chr>, first_land <chr>,
## # first_visit <fct>
fc_LocVSound$first_visit <- factor(fc_LocVSound$first_visit, levels = c("location", "sound", "neither")) #redo factor order, removes extra levels
unique(fc_LocVSound$first_visit)
## [1] location neither <NA> sound
## Levels: location sound neither
# This does the same thing, but makes a new dataframe to do it
#summarize occurances
first_visits_LvS <- as.data.frame(table(fc_LocVSound$first_visit, fc_LocVSound$Species)) #summarized by species into table
names(first_visits_LvS)<- c("Cue", "Species", "Visits")
## For plotting purposes, need to replace 0's with a small number, not meaningful
first_visits_LvS_fp <- first_visits_LvS #first visits for plot
first_visits_LvS_fp[first_visits_LvS_fp == 0] <- 0.03
#reorder factor
#first_visits_LvS_fp$Cue<- factor(first_visits_LvS_fp$Cue, levels = c("location", "sound", "neither", "nearest"))
#View(first_visits_LvS_fp)
first_visits_LvS_wide <- dcast(first_visits_LvS, Cue~Species ) #reshapes into wide format
## Using Visits as value column: use value.var to override.
head(first_visits_LvS_wide)
## Cue AJ L
## 1 location 9 5
## 2 sound 1 1
## 3 neither 2 3
Did the bats visit the platforms first equally? Did the species visit differently?
Did the bats visit the platforms equally? Independent variable: 0 Dependent variable: # first visits to 3 platforms, compared to random
## MUST CHANGE THESE NUMBERS MANUALLY ##
# Did the AJs visit the three platforms equally?
# Use exact multinomial test: categorical data, small sample sizes
# AJs are in column #2:
observed_LvS_AJ <- c(first_visits_LvS_wide[first_visits_LvS_wide=="location", 2], first_visits_LvS_wide[first_visits_LvS_wide=="neither", 2], first_visits_LvS_wide[first_visits_LvS_wide=="sound", 2])
observed_LvS_AJ #observed number of visits to the three different platforms
## [1] 9 2 1
prob <- rep(0.33, 3) #expected number of visits if they are all equal
prob
## [1] 0.33 0.33 0.33
mult_test_LvS_AJ <- multinomial.test(observed_LvS_AJ, prob) #exact multinomial test
##
## Exact Multinomial Test, distance measure: p
##
## Events pObs p.value
## 91 0.0012 0.0172
mult_test_LvS_AJ # p = 0.0172
## $id
## [1] "Exact Multinomial Test"
##
## $size
## [1] 12
##
## $groups
## [1] 3
##
## $stat
## [1] "lowP"
##
## $allProb
## [1] 6.520009e-02 5.216007e-02 5.216007e-02 5.216007e-02 5.216007e-02
## [6] 5.216007e-02 5.216007e-02 3.477338e-02 3.477338e-02 3.477338e-02
## [11] 3.129604e-02 3.129604e-02 3.129604e-02 2.608004e-02 2.608004e-02
## [16] 2.608004e-02 2.608004e-02 2.608004e-02 2.608004e-02 1.490288e-02
## [21] 1.490288e-02 1.490288e-02 1.490288e-02 1.490288e-02 1.490288e-02
## [26] 1.043201e-02 1.043201e-02 1.043201e-02 1.043201e-02 1.043201e-02
## [31] 1.043201e-02 7.451439e-03 7.451439e-03 7.451439e-03 7.451439e-03
## [36] 7.451439e-03 7.451439e-03 5.588579e-03 5.588579e-03 5.588579e-03
## [41] 3.725719e-03 3.725719e-03 3.725719e-03 3.725719e-03 3.725719e-03
## [46] 3.725719e-03 1.738669e-03 1.738669e-03 1.738669e-03 1.490288e-03
## [51] 1.490288e-03 1.490288e-03 1.490288e-03 1.490288e-03 1.490288e-03
## [56] 1.241906e-03 1.241906e-03 1.241906e-03 1.241906e-03 1.241906e-03
## [61] 1.241906e-03 9.314298e-04 9.314298e-04 9.314298e-04 9.314298e-04
## [66] 9.314298e-04 9.314298e-04 4.139688e-04 4.139688e-04 4.139688e-04
## [71] 4.139688e-04 4.139688e-04 4.139688e-04 2.483813e-04 2.483813e-04
## [76] 2.483813e-04 1.241906e-04 1.241906e-04 1.241906e-04 1.241906e-04
## [81] 1.241906e-04 1.241906e-04 2.258012e-05 2.258012e-05 2.258012e-05
## [86] 2.258012e-05 2.258012e-05 2.258012e-05 1.881676e-06 1.881676e-06
## [91] 1.881676e-06
##
## $ntrial
## NULL
##
## $p.value
## [1] 0.0172
#####What kind of posthocs? Do A binomial test, with the treatment in question, and the sum of the other treatments, and then do a Boneferroni correction: divide the significance level by the number of comparisons. My significance value is: 0.0167
#http://www.biostathandbook.com/exactgof.html
observed_LvS_AJ
## [1] 9 2 1
prob2<- c(.33, .66)
obs_LvS_AJ_loc<-c(9,3)
obs_LvS_AJ_sound <- c(1, 11)
obs_LvS_AJ_neither <- c(2, 10)
#Boneferroni: .0125 significance for posthocs
multinomial.test(obs_LvS_AJ_loc, prob2) # p=0.0039 (significance )
##
## Exact Multinomial Test, distance measure: p
##
## Events pObs p.value
## 13 0.0033 0.0039
multinomial.test(obs_LvS_AJ_sound, prob2) #p = 0.0727
##
## Exact Multinomial Test, distance measure: p
##
## Events pObs p.value
## 13 0.0462 0.0727
multinomial.test(obs_LvS_AJ_neither, prob2) # p = 0.3588
##
## Exact Multinomial Test, distance measure: p
##
## Events pObs p.value
## 13 0.1272 0.3588
# Exact multinomial test suggests that This is more visits to Location that expected at random
So AJs went to Sound more than the other places
## MUST CHANGE THESE NUMBERS MANUALLY ##
# Did the Lophos visit the three platforms equally?
# Use exact multinomial test: categorical data, small sample sizes
# Ls are in column #2:
observed_LvS_L <- c(first_visits_LvS_wide[first_visits_LvS_wide=="location", 3], first_visits_LvS_wide[first_visits_LvS_wide=="neither", 3], first_visits_LvS_wide[first_visits_LvS_wide=="sound", 3])
observed_LvS_L #observed number of visits to the three different platforms
## [1] 5 3 1
prob <- rep(0.33, 3) #expected number of visits if they are all equal
prob
## [1] 0.33 0.33 0.33
mult_test_LvS_L <- multinomial.test(observed_LvS_L, prob) #exact multinomial test
##
## Exact Multinomial Test, distance measure: p
##
## Events pObs p.value
## 55 0.0256 0.3193
mult_test_LvS_L # 0.3193
## $id
## [1] "Exact Multinomial Test"
##
## $size
## [1] 9
##
## $groups
## [1] 3
##
## $stat
## [1] "lowP"
##
## $allProb
## [1] 8.535284e-02 6.401463e-02 6.401463e-02 6.401463e-02 6.401463e-02
## [6] 6.401463e-02 6.401463e-02 3.840878e-02 3.840878e-02 3.840878e-02
## [11] 3.200732e-02 3.200732e-02 3.200732e-02 2.560585e-02 2.560585e-02
## [16] 2.560585e-02 2.560585e-02 2.560585e-02 2.560585e-02 1.280293e-02
## [21] 1.280293e-02 1.280293e-02 1.280293e-02 1.280293e-02 1.280293e-02
## [26] 6.401463e-03 6.401463e-03 6.401463e-03 6.401463e-03 6.401463e-03
## [31] 6.401463e-03 4.267642e-03 4.267642e-03 4.267642e-03 4.267642e-03
## [36] 4.267642e-03 4.267642e-03 3.657979e-03 3.657979e-03 3.657979e-03
## [41] 1.828989e-03 1.828989e-03 1.828989e-03 1.828989e-03 1.828989e-03
## [46] 1.828989e-03 4.572474e-04 4.572474e-04 4.572474e-04 4.572474e-04
## [51] 4.572474e-04 4.572474e-04 5.080526e-05 5.080526e-05 5.080526e-05
##
## $ntrial
## NULL
##
## $p.value
## [1] 0.3193
# Exact multinomial test suggests that this is not different than random, no posthocs needed 0.3193
prob2<- c(.33, .66)
obs_LvS_L_loc<-c(5,4)
obs_LvS_L_sound <- c(1, 8)
obs_LvS_L_neither <- c(3, 6)
#Boneferroni: .0125 significance for posthocs
multinomial.test(obs_LvS_L_loc, prob2) # p=0.1709
##
## Exact Multinomial Test, distance measure: p
##
## Events pObs p.value
## 10 0.1024 0.1709
multinomial.test(obs_LvS_L_sound, prob2) #p = 0.2879
##
## Exact Multinomial Test, distance measure: p
##
## Events pObs p.value
## 10 0.1171 0.2879
multinomial.test(obs_LvS_L_neither, prob2) # p = 0.2731
##
## Exact Multinomial Test, distance measure: p
##
## Events pObs p.value
## 10 0.2731 1
Can reject null hypothesis that Lophostoma went to the 3 cues first equally p= 0.0172
First_visits_LvS_p <- ggplot(data =first_visits_LvS_fp, aes(x = Cue, y = Visits, fill = Species ))
First_visits_LvS_p <- First_visits_LvS_p + geom_bar(stat = "identity", position=position_dodge()) # need stat = identity bc just not jsut counting occurances in datasheet
First_visits_LvS_p <- First_visits_LvS_p + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
First_visits_LvS_p <- First_visits_LvS_p + scale_x_discrete( labels=c("location" = "Location", "sound" = "Sound","neither" = "Neither")) # Relabelling X axis #rearrange bars
First_visits_LvS_p <- First_visits_LvS_p + xlab("Cues")
First_visits_LvS_p <- First_visits_LvS_p + ylab("Total visits")
First_visits_LvS_p <- First_visits_LvS_p + scale_fill_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
First_visits_LvS_p
#ggsave("Loc_v_sound_first_visit.png")
# rm(First_visits_p)
head(LocVSmell)
## # A tibble: 6 x 31
## Bat.ID Scorer Date Time Species Treatment Rewarded_loc Rewarded_smell
## <chr> <chr> <chr> <chr> <chr> <chr> <dbl> <chr>
## 1 A-C095 unkno… 3/30… 23:56 AJ LocVSmell 42 sasafrass
## 2 D-C0B6 unkno… 3/31… 22:29 AJ LocVSmell 42 sasafrass
## 3 C-C09A unkno… 4/1/… <NA> AJ LocVSmell 42 sasafrass
## 4 L-C07F unkno… 4/30… 23:13 AJ LocVSmell 33 cinnamon
## 5 A-Head Dylan 7/3/… 19:11 L LocVSmell 31 cinnamon
## 6 B-Butt Dylan 6/30… 19:30 L LocVSmell 31 cinnamon
## # ... with 23 more variables: first_hover <chr>, first_land <chr>,
## # first_visit <chr>, lands_loc <int>, hovers_loc <int>,
## # visits_loc <int>, lands_smell <int>, hovers_smell <int>,
## # visits_smell <int>, lands_neither <int>, hovers_neither <int>,
## # visits_neither <int>, visits_nearest <int>, visits_sassafras <int>,
## # visits_almond <int>, visits_cinnamon <int>, visits_anise <int>,
## # total_lands <int>, total_hovers <int>, total_visits <int>,
## # pct_visits_loc <dbl>, pct_visits_smell <dbl>, pct_visits_neither <dbl>
## make a subset with only lophos and AJs, remove Trachops as factor level
LocVSmell_AJ_L= subset(LocVSmell, LocVSmell$Species != "T")
##View(LocVSmell_AJ_L)
LocVSmell_AJ_L$Species<- factor(LocVSmell_AJ_L$Species)
head(LocVSmell_AJ_L)
## # A tibble: 6 x 31
## Bat.ID Scorer Date Time Species Treatment Rewarded_loc Rewarded_smell
## <chr> <chr> <chr> <chr> <fct> <chr> <dbl> <chr>
## 1 A-C095 unkno… 3/30… 23:56 AJ LocVSmell 42 sasafrass
## 2 D-C0B6 unkno… 3/31… 22:29 AJ LocVSmell 42 sasafrass
## 3 C-C09A unkno… 4/1/… <NA> AJ LocVSmell 42 sasafrass
## 4 L-C07F unkno… 4/30… 23:13 AJ LocVSmell 33 cinnamon
## 5 A-Head Dylan 7/3/… 19:11 L LocVSmell 31 cinnamon
## 6 B-Butt Dylan 6/30… 19:30 L LocVSmell 31 cinnamon
## # ... with 23 more variables: first_hover <chr>, first_land <chr>,
## # first_visit <chr>, lands_loc <int>, hovers_loc <int>,
## # visits_loc <int>, lands_smell <int>, hovers_smell <int>,
## # visits_smell <int>, lands_neither <int>, hovers_neither <int>,
## # visits_neither <int>, visits_nearest <int>, visits_sassafras <int>,
## # visits_almond <int>, visits_cinnamon <int>, visits_anise <int>,
## # total_lands <int>, total_hovers <int>, total_visits <int>,
## # pct_visits_loc <dbl>, pct_visits_smell <dbl>, pct_visits_neither <dbl>
#levels(LocVSmell_AJ_L$Species)
SUMMARIZING AVERAGE proportion of visits to each cue
# summarize average visits per species using dplyr
# summarize number
# seperate out the species
#look at histograms of responses
# run kruskal wallace? Anova with percents?
# Make graphs: percentage choices for each species
#
Avg_pct_visits<-LocVSmell_AJ_L %>% group_by(Species) %>%
summarise(avg_sound = mean(pct_visits_loc, na.rm=TRUE), avg_smell = mean(pct_visits_smell, na.rm=TRUE),avg_neither = mean(pct_visits_neither, na.rm=TRUE) )
Avg_pct_visits
## # A tibble: 2 x 4
## Species avg_sound avg_smell avg_neither
## <fct> <dbl> <dbl> <dbl>
## 1 AJ 0.560 0.252 0.180
## 2 L 0.738 0.0769 0.189
SUMMARIZING AVERAGE number of of visits overall, per species
### Can also look at the absolute number of times that a given species visits or lands on a platform (total visits)
## summary of the mean of the total visits / species mean of the total lands / species, mean of the total hovers/ species
Avg_visits_spc<-LocVSmell_AJ_L %>% group_by(Species) %>%
summarise(avg_vis = mean(total_visits, na.rm=TRUE), sd_vis = sd(total_visits), avg_lands = mean(total_lands, na.rm=TRUE), sd_lands = sd(total_lands), avg_hovers = mean(total_hovers, na.rm=TRUE), sd_hovers = sd(total_hovers) )
Avg_visits_spc
## # A tibble: 2 x 7
## Species avg_vis sd_vis avg_lands sd_lands avg_hovers sd_hovers
## <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 AJ 16.7 NA 0.636 NA 15.9 NA
## 2 L 41.7 26.7 21.2 20.2 20.7 10.6
class(Avg_visits_spc)
## [1] "tbl_df" "tbl" "data.frame"
#seems like lophos may go the the platforms more on average. At a glance:
t.test(LocVSmell_AJ_L$total_visits[LocVSmell_AJ_L$Species =="AJ"], LocVSmell_AJ_L$total_visits[LocVSmell_AJ_L$Species =="L"])
##
## Welch Two Sample t-test
##
## data: LocVSmell_AJ_L$total_visits[LocVSmell_AJ_L$Species == "AJ"] and LocVSmell_AJ_L$total_visits[LocVSmell_AJ_L$Species == "L"]
## t = -2.6735, df = 12.875, p-value = 0.01927
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -45.17252 -4.77293
## sample estimates:
## mean of x mean of y
## 16.72727 41.70000
# At least here, seems that lohpo visit and land more often
## basically assessing normality
hist(LocVSmell_AJ_L$pct_visits_smell[LocVSmell_AJ_L$Species=="L"], breaks=6)
#not particularly normal
head(LocVSmell_AJ_L)
## # A tibble: 6 x 31
## Bat.ID Scorer Date Time Species Treatment Rewarded_loc Rewarded_smell
## <chr> <chr> <chr> <chr> <fct> <chr> <dbl> <chr>
## 1 A-C095 unkno… 3/30… 23:56 AJ LocVSmell 42 sasafrass
## 2 D-C0B6 unkno… 3/31… 22:29 AJ LocVSmell 42 sasafrass
## 3 C-C09A unkno… 4/1/… <NA> AJ LocVSmell 42 sasafrass
## 4 L-C07F unkno… 4/30… 23:13 AJ LocVSmell 33 cinnamon
## 5 A-Head Dylan 7/3/… 19:11 L LocVSmell 31 cinnamon
## 6 B-Butt Dylan 6/30… 19:30 L LocVSmell 31 cinnamon
## # ... with 23 more variables: first_hover <chr>, first_land <chr>,
## # first_visit <chr>, lands_loc <int>, hovers_loc <int>,
## # visits_loc <int>, lands_smell <int>, hovers_smell <int>,
## # visits_smell <int>, lands_neither <int>, hovers_neither <int>,
## # visits_neither <int>, visits_nearest <int>, visits_sassafras <int>,
## # visits_almond <int>, visits_cinnamon <int>, visits_anise <int>,
## # total_lands <int>, total_hovers <int>, total_visits <int>,
## # pct_visits_loc <dbl>, pct_visits_smell <dbl>, pct_visits_neither <dbl>
Do AJs go to one platform more than another? Do Lophostoma go to any platforms more than one another? Which? Is there a difference between AJs and lophostoma? (anova? )
# pull out just the relevent columns:
LocVSmell_AJ_L_pcts<- LocVSmell_AJ_L[ , c("Bat.ID", "Species", "pct_visits_loc", "pct_visits_smell", "pct_visits_neither" )]
head(LocVSmell_AJ_L_pcts)
## # A tibble: 6 x 5
## Bat.ID Species pct_visits_loc pct_visits_smell pct_visits_neither
## <chr> <fct> <dbl> <dbl> <dbl>
## 1 A-C095 AJ 0.667 0.333 0
## 2 D-C0B6 AJ 1 0 0
## 3 C-C09A AJ 0.692 0.154 0.0769
## 4 L-C07F AJ 0.583 0.208 0.208
## 5 A-Head L 0.85 0.15 0
## 6 B-Butt L 0.862 0 0.138
## Alternatively could just put all the rows I don't want melted into "id" in the following fuction.
colnames(LocVSmell_AJ_L_pcts)
## [1] "Bat.ID" "Species" "pct_visits_loc"
## [4] "pct_visits_smell" "pct_visits_neither"
mLocVSmell <- melt(LocVSmell_AJ_L_pcts, id=c("Bat.ID","Species"))
head(mLocVSmell)
## Bat.ID Species variable value
## 1 A-C095 AJ pct_visits_loc 0.6666667
## 2 D-C0B6 AJ pct_visits_loc 1.0000000
## 3 C-C09A AJ pct_visits_loc 0.6923077
## 4 L-C07F AJ pct_visits_loc 0.5833333
## 5 A-Head L pct_visits_loc 0.8500000
## 6 B-Butt L pct_visits_loc 0.8620690
#rm(mLocVSmell )
# pull out just the relevent columns:
LocVSmell_AJ_L_cnts<- LocVSmell_AJ_L[ , c("Bat.ID", "Species", "visits_loc", "visits_smell", "visits_neither" )]
head(LocVSmell_AJ_L_cnts)
## # A tibble: 6 x 5
## Bat.ID Species visits_loc visits_smell visits_neither
## <chr> <fct> <int> <int> <int>
## 1 A-C095 AJ 4 2 0
## 2 D-C0B6 AJ 2 0 0
## 3 C-C09A AJ 18 4 2
## 4 L-C07F AJ 14 5 5
## 5 A-Head L 34 6 0
## 6 B-Butt L 25 0 4
## Alternatively could just put all the rows I don't want melted into "id" in the following fuction, which would save the rest of the data
colnames(LocVSmell_AJ_L_cnts)
## [1] "Bat.ID" "Species" "visits_loc" "visits_smell"
## [5] "visits_neither"
mLocVSmell_cnts <- melt(LocVSmell_AJ_L_cnts, id=c("Bat.ID","Species"))
head(mLocVSmell_cnts)
## Bat.ID Species variable value
## 1 A-C095 AJ visits_loc 4
## 2 D-C0B6 AJ visits_loc 2
## 3 C-C09A AJ visits_loc 18
## 4 L-C07F AJ visits_loc 14
## 5 A-Head L visits_loc 34
## 6 B-Butt L visits_loc 25
## convenient also to just add this count value to mLocVSmell
visits_counts<-mLocVSmell_cnts$value
mLocVSmell <-cbind(mLocVSmell, visits_counts)
" Did the bats fly to the three platforms the same amount?" AJS #### Kruskal-wallace: AJ
LvSm_AJ_k.test<- kruskal.test(value ~ variable, data =mLocVSmell[mLocVSmell$Species =="AJ", ] )
LvSm_AJ_k.test
##
## Kruskal-Wallis rank sum test
##
## data: value by variable
## Kruskal-Wallis chi-squared = 12.645, df = 2, p-value = 0.001796
LvSm_AJ_count_k.test<- kruskal.test(value ~ variable, data =mLocVSmell_cnts[mLocVSmell_cnts$Species =="AJ", ] )
LvSm_AJ_count_k.test
##
## Kruskal-Wallis rank sum test
##
## data: value by variable
## Kruskal-Wallis chi-squared = 2.9843, df = 2, p-value = 0.2249
Significant difference, so post-hocs
LvSm_L_k.test<- kruskal.test(value ~ variable, data =mLocVSmell[mLocVSmell$Species =="L", ] )
LvSm_L_k.test
##
## Kruskal-Wallis rank sum test
##
## data: value by variable
## Kruskal-Wallis chi-squared = 17.112, df = 2, p-value = 0.0001924
LvSm_L_cnts_k.test<- kruskal.test(value ~ variable, data =mLocVSmell_cnts[mLocVSmell_cnts$Species =="L", ] )
LvSm_L_cnts_k.test
##
## Kruskal-Wallis rank sum test
##
## data: value by variable
## Kruskal-Wallis chi-squared = 11.386, df = 2, p-value = 0.00337
Significant difference, so post-hocs
“Which platforms did the bats fly to more, which were different?”
LvSm_AJ_wilhox = pairwise.wilcox.test(mLocVSmell[mLocVSmell$Species =="AJ", ]$value, mLocVSmell[mLocVSmell$Species =="AJ", ]$variable, p.adjust.method=p.adjust.methods)
## Warning in wilcox.test.default(xi, xj, paired = paired, ...): cannot
## compute exact p-value with ties
## Warning in wilcox.test.default(xi, xj, paired = paired, ...): cannot
## compute exact p-value with ties
## Warning in wilcox.test.default(xi, xj, paired = paired, ...): cannot
## compute exact p-value with ties
LvSm_AJ_wilhox
##
## Pairwise comparisons using Wilcoxon rank sum test
##
## data: mLocVSmell[mLocVSmell$Species == "AJ", ]$value and mLocVSmell[mLocVSmell$Species == "AJ", ]$variable
##
## pct_visits_loc pct_visits_smell
## pct_visits_smell 0.0094 -
## pct_visits_neither 0.0060 0.4515
##
## P value adjustment method: holm
LvSm_L_wilhox = pairwise.wilcox.test(mLocVSmell[mLocVSmell$Species =="L", ]$value, mLocVSmell[mLocVSmell$Species =="L", ]$variable, p.adjust.method=p.adjust.methods)
## Warning in wilcox.test.default(xi, xj, paired = paired, ...): cannot
## compute exact p-value with ties
## Warning in wilcox.test.default(xi, xj, paired = paired, ...): cannot
## compute exact p-value with ties
## Warning in wilcox.test.default(xi, xj, paired = paired, ...): cannot
## compute exact p-value with ties
LvSm_L_wilhox
##
## Pairwise comparisons using Wilcoxon rank sum test
##
## data: mLocVSmell[mLocVSmell$Species == "L", ]$value and mLocVSmell[mLocVSmell$Species == "L", ]$variable
##
## pct_visits_loc pct_visits_smell
## pct_visits_smell 0.00068 -
## pct_visits_neither 0.00237 0.60645
##
## P value adjustment method: holm
LvSm_AJ_dunn<-dunnTest(mLocVSmell[mLocVSmell$Species =="AJ", ]$value, mLocVSmell[mLocVSmell$Species =="AJ", ]$variable, method="holm", kw=TRUE)
## Warning: Some rows deleted from 'x' and 'g' because missing data.
LvSm_AJ_dunn
## Dunn (1964) Kruskal-Wallis multiple comparison
## p-values adjusted with the Holm method.
## Comparison Z P.unadj
## 1 pct_visits_loc - pct_visits_neither 3.3438290 0.0008263064
## 2 pct_visits_loc - pct_visits_smell 2.7196476 0.0065351517
## 3 pct_visits_neither - pct_visits_smell -0.6241814 0.5325084468
## P.adj
## 1 0.002478919
## 2 0.013070303
## 3 0.532508447
,./##Dunn test post hoc: Lopho
LvSm_L_dunn<-dunnTest(mLocVSmell[mLocVSmell$Species =="L", ]$value, mLocVSmell[mLocVSmell$Species =="L", ]$variable, method="holm", kw=TRUE)
LvSm_L_dunn
## Dunn (1964) Kruskal-Wallis multiple comparison
## p-values adjusted with the Holm method.
## Comparison Z P.unadj
## 1 pct_visits_loc - pct_visits_neither 3.2969971 0.0009772451
## 2 pct_visits_loc - pct_visits_smell 3.8121529 0.0001377616
## 3 pct_visits_neither - pct_visits_smell 0.5151558 0.6064441548
## P.adj
## 1 0.0019544902
## 2 0.0004132848
## 3 0.6064441548
#proportion data
boxplot(value ~ variable* Species, data = mLocVSmell) #box width of largest looks more than 2x larger than that of smaller
bartlett.test( value ~ interaction(variable, Species), data = mLocVSmell) #Bartlett test shows variances are different
##
## Bartlett test of homogeneity of variances
##
## data: value by interaction(variable, Species)
## Bartlett's K-squared = 12.712, df = 5, p-value = 0.02623
# proportions don't have normal variance
# Count data also does not have homogenaity of variances
boxplot(value ~ variable* Species, data = mLocVSmell_cnts)
bartlett.test( value ~ interaction(variable, Species), data = mLocVSmell_cnts)
##
## Bartlett test of homogeneity of variances
##
## data: value by interaction(variable, Species)
## Bartlett's K-squared = 30.06, df = 5, p-value = 1.435e-05
# does not have homogenaity of variance
mLocVSmell_cnts$value_sqrt<- (sqrt(mLocVSmell_cnts$value)) #sqrt transformation
mLocVSmell_cnts$value_cub = sign(mLocVSmell_cnts$value) * abs(mLocVSmell_cnts$value)^(1/3) #cubed transformation
mLocVSmell$value_log<- (log(mLocVSmell$value))#log transformation- too strong
mLocVSmell$value_sqrt<- (sqrt(mLocVSmell$value)) #sqrt transformation
mLocVSmell$value_cub = sign(mLocVSmell$value) * abs(mLocVSmell_cnts$value)^(1/3) #cubed transformation
mLocVSmell$value_log<- (log(mLocVSmell$value))#log transformation- too strong
boxplot(value ~ variable* Species, data = mLocVSmell) #original
boxplot(value_sqrt ~ variable* Species, data = mLocVSmell) #sqrt
boxplot(value_cub ~ variable* Species, data = mLocVSmell) #cub, pretty good
boxplot(value_log ~ variable* Species, data = mLocVSmell) # too strong
## Warning in bplt(at[i], wid = width[i], stats = z$stats[, i], out =
## z$out[z$group == : Outlier (-Inf) in boxplot 2 is not drawn
## Warning in bplt(at[i], wid = width[i], stats = z$stats[, i], out =
## z$out[z$group == : Outlier (-Inf) in boxplot 3 is not drawn
#counts
boxplot(value ~ variable* Species, data = mLocVSmell_cnts) #original
boxplot(value_sqrt ~ variable* Species, data = mLocVSmell_cnts) #sqrt, prob best
boxplot(value_cub ~ variable* Species, data = mLocVSmell_cnts) #cub,
#boxplot(value_log ~ variable* Species, data = mLocVSmell_cnts) # too strong
bartlett.test( value_sqrt ~ interaction(variable, Species), data = mLocVSmell)
##
## Bartlett test of homogeneity of variances
##
## data: value_sqrt by interaction(variable, Species)
## Bartlett's K-squared = 6.7637, df = 5, p-value = 0.2388
bartlett.test( value_sqrt ~ interaction(variable, Species), data = mLocVSmell_cnts)
##
## Bartlett test of homogeneity of variances
##
## data: value_sqrt by interaction(variable, Species)
## Bartlett's K-squared = 8.4282, df = 5, p-value = 0.1342
## This actually seems to have fixed the homogenaity of variances problem
#normality? Less important, ANOVAs are robust against this violation
#proportions:
hist(mLocVSmell$value[mLocVSmell$Species=="L"], breaks=6)
hist(mLocVSmell$value_sqrt[mLocVSmell$Species=="L"], breaks=6)
#hist(mLocVSmell$value_cub[mLocVSmell$Species=="L"], breaks=6)
#counts:
hist(mLocVSmell_cnts$value[mLocVSmell_cnts$Species=="L"], breaks=6)
hist(mLocVSmell_cnts$value_sqrt[mLocVSmell_cnts$Species=="L"], breaks=6)
hist(mLocVSmell_cnts$value_cub[mLocVSmell_cnts$Species=="L"], breaks=6)
#hist(mLocVSmell_cnts$value_log[mLocVSmell_cnts$Species=="L"], breaks=8)
str(mLocVSmell_cnts)
## 'data.frame': 66 obs. of 6 variables:
## $ Bat.ID : chr "A-C095" "D-C0B6" "C-C09A" "L-C07F" ...
## $ Species : Factor w/ 2 levels "AJ","L": 1 1 1 1 2 2 2 1 1 2 ...
## $ variable : Factor w/ 3 levels "visits_loc","visits_smell",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ value : int 4 2 18 14 34 25 33 0 0 29 ...
## $ value_sqrt: num 2 1.41 4.24 3.74 5.83 ...
## $ value_cub : num 1.59 1.26 2.62 2.41 3.24 ...
table(mLocVSmell_cnts$value)
##
## 0 2 3 4 5 6 8 9 10 12 13 14 15 16 18 19 20 25 29 33 34 36 42 55
## 18 4 3 5 4 4 2 1 2 2 1 2 1 2 1 2 1 1 1 2 1 1 1 1
sum(mLocVSmell_cnts$value == 0)
## [1] NA
## the logged values look good but ruin the homogency of variance
##
##View(mLocVSmell_cnts)
library(car)
anova_LvSm <- aov(value_sqrt ~ Species*variable, data=mLocVSmell_cnts)
anova_LvSm
## Call:
## aov(formula = value_sqrt ~ Species * variable, data = mLocVSmell_cnts)
##
## Terms:
## Species variable Species:variable Residuals
## Sum of Squares 16.20933 54.09942 21.20349 154.71499
## Deg. of Freedom 1 2 2 57
##
## Residual standard error: 1.647513
## Estimated effects may be unbalanced
## 3 observations deleted due to missingness
Anova(anova_LvSm, type = 2)
## Anova Table (Type II tests)
##
## Response: value_sqrt
## Sum Sq Df F value Pr(>F)
## Species 16.209 1 5.9718 0.0176548 *
## variable 54.099 2 9.9656 0.0001943 ***
## Species:variable 21.203 2 3.9059 0.0257215 *
## Residuals 154.715 57
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Anova(anova_LvSm, type = 3)
## Anova Table (Type III tests)
##
## Response: value_sqrt
## Sum Sq Df F value Pr(>F)
## (Intercept) 67.172 1 24.7475 6.352e-06 ***
## Species 33.782 1 12.4458 0.0008356 ***
## variable 6.257 2 1.1525 0.3230801
## Species:variable 21.203 2 3.9059 0.0257215 *
## Residuals 154.715 57
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Could get the mean proportion of visits to cues from each of the species. bootstrap the mean proportion, then compare the 95% confidence intervals for each mean
############CODE FROM BASTI#################################################
#X will be the vector of proportions or rates or counts for one treatment in a species. It will calculate 5000 means based on re-sampling your data and then calculate the confidence intervals from that mean-distribution.
#The function spits out a vector of three values, the lower CI, mean, and upper CI.
#This is the function used for it:
#https://www.rdocumentation.org/packages/boot/versions/1.3-20/topics/boot.ci
###########################################################################
#mean function
mean.w <- function(x,w) sum(x*w) # calculates a mean
#bootstrapped confidence intervals function
boot_ci <- function(x){
mean <- mean(x)
low <- boot.ci(boot(data=x, statistic=mean.w, R=5000, stype="w"), type="basic")$basic[1,4]
high <- boot.ci(boot(data=x, statistic=mean.w, R=5000, stype="w"), type="basic")$basic[1,5]
c(low,mean,high)} # bootstraps the confidence intervals
## get rid of NAs in data using complete.cases
mLocVSmell_na<-mLocVSmell[complete.cases(mLocVSmell[ ,4:8]), ] #removes NA rows in value columns 4:6, this might not make sense if I change the number of columns
head(mLocVSmell)
## Bat.ID Species variable value visits_counts value_log
## 1 A-C095 AJ pct_visits_loc 0.6666667 4 -0.4054651
## 2 D-C0B6 AJ pct_visits_loc 1.0000000 2 0.0000000
## 3 C-C09A AJ pct_visits_loc 0.6923077 18 -0.3677248
## 4 L-C07F AJ pct_visits_loc 0.5833333 14 -0.5389965
## 5 A-Head L pct_visits_loc 0.8500000 34 -0.1625189
## 6 B-Butt L pct_visits_loc 0.8620690 25 -0.1484200
## value_sqrt value_cub
## 1 0.8164966 1.587401
## 2 1.0000000 1.259921
## 3 0.8320503 2.620741
## 4 0.7637626 2.410142
## 5 0.9219544 3.239612
## 6 0.9284767 2.924018
#New database without NAs in the selected columns
LocVSmell_AJ_L_na <- LocVSmell_AJ_L[complete.cases(LocVSmell_AJ_L[ ,c("visits_loc", "visits_smell", "visits_neither", "pct_visits_loc", "pct_visits_smell", "pct_visits_neither")]), ]
#The CI's for sound v Smell, percentages
set.seed(1)
LvSm_pct_CI <- do.call(data.frame,aggregate(value ~ Species + variable , boot_ci, data = mLocVSmell_na)) #This applies the bootstrap accross species and treatment variables, and do.call puts the data.frame in the right format
colnames(LvSm_pct_CI) <- c("Species", "variable", "low", "mean", "high")
# The CIs for sound V Smell, counts
LvSm_count_CI <- do.call(data.frame, aggregate(visits_counts ~ Species + variable , boot_ci, data = mLocVSmell_na))
head(LvSm_count_CI)
## Species variable visits_counts.V1 visits_counts.V2
## 1 AJ pct_visits_loc 6.111111 10.111111
## 2 L pct_visits_loc 17.900000 26.600000
## 3 AJ pct_visits_smell 2.444444 6.000000
## 4 L pct_visits_smell 0.400000 4.200000
## 5 AJ pct_visits_neither 2.111111 4.111111
## 6 L pct_visits_neither 1.300000 11.100000
## visits_counts.V3
## 1 14.000000
## 2 33.900000
## 3 9.111111
## 4 6.900000
## 5 6.000000
## 6 19.697492
colnames(LvSm_count_CI) <- c("Species", "variable", "low", "mean", "high")
#LvSm_pct_CI$Species <- factor(LvSm_pct_CI$Species, levels=c("AJ", "L"), labels = c("A. jamaicensis", "L. silvicolum")) #need to do this for plot legends to say full name
#LvSm_count_CI$Species <- factor(LvSm_count_CI$Species, levels=c("AJ", "L"), labels = c("A. jamaicensis", "L. silvicolum"))
pd = position_dodge(0.5) # move bars .05 to the left and right
#proportion plot
LvSm_pct_CI_p <- ggplot(data = LvSm_pct_CI, aes(x=variable, y = mean, colour = Species))
LvSm_pct_CI_p <- LvSm_pct_CI_p + geom_errorbar(aes(ymin = low, ymax = high), width =.1, position = pd)
LvSm_pct_CI_p <- LvSm_pct_CI_p + geom_point( position = pd, shape=18, size = 3)
LvSm_pct_CI_p <- LvSm_pct_CI_p + scale_fill_discrete(name="My new legend", labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
LvSm_pct_CI_p <- LvSm_pct_CI_p + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
LvSm_pct_CI_p <- LvSm_pct_CI_p + scale_x_discrete(labels=c("pct_visits_sound" = "Location", "pct_visits_smell" = "Smell",
"pct_visits_neither" = "Neither" )) # Relabelling X axis
LvSm_pct_CI_p <- LvSm_pct_CI_p + xlab("Cues")
LvSm_pct_CI_p <- LvSm_pct_CI_p + ylab("Mean proportion of visits")
LvSm_pct_CI_p <- LvSm_pct_CI_p + scale_color_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
LvSm_pct_CI_p
#ggsave("LvSm_pct_CI_p.png")
#count plot
LvSm_count_CI_p <- ggplot(data = LvSm_count_CI, aes(x=variable, y = mean, colour = Species))
LvSm_count_CI_p <- LvSm_count_CI_p + geom_errorbar(aes(ymin = low, ymax = high), width =.1, position = pd)
LvSm_count_CI_p <- LvSm_count_CI_p + geom_point( position = pd, shape=18, size = 3)
LvSm_count_CI_p <- LvSm_count_CI_p + scale_fill_discrete(name="My new legend", labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
LvSm_count_CI_p <- LvSm_count_CI_p + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
LvSm_count_CI_p <- LvSm_count_CI_p + scale_x_discrete(labels=c("pct_visits_loc" = "Location", "pct_visits_smell" = "Smell",
"pct_visits_neither" = "Neither" )) # Relabelling X axis
LvSm_count_CI_p <- LvSm_count_CI_p + xlab("Cues")
LvSm_count_CI_p <- LvSm_count_CI_p + ylab("Mean number of visits")
LvSm_count_CI_p <- LvSm_count_CI_p + scale_color_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
LvSm_count_CI_p
#ggsave("LvSm_count_CI_p.png" )
LocVSmell_bar <- ggplot(data =mLocVSmell, aes(x = variable, y = value))
LocVSmell_bar <- LocVSmell_bar + geom_boxplot(aes(fill=Species))
LocVSmell_bar <- LocVSmell_bar + geom_point(position=position_dodge(width=0.75), aes(group=Species), alpha = 1/4) #makes points semi-transparent
LocVSmell_bar <- LocVSmell_bar + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
LocVSmell_bar <- LocVSmell_bar + xlab("Cues")
LocVSmell_bar <- LocVSmell_bar + ylab("Proportion of total visits")
LocVSmell_bar <- LocVSmell_bar + scale_x_discrete(labels=c("pct_visits_sound" = "Location", "pct_visits_smell" = "Smell",
"pct_visits_neither" = "Neither" )) # Relabelling X axis
LocVSmell_bar <- LocVSmell_bar + scale_fill_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
LocVSmell_bar
## Warning: Removed 9 rows containing non-finite values (stat_boxplot).
## Warning: Removed 9 rows containing missing values (geom_point).
##ggsave("LocVSmell.png")
LocVSmell_bar_cnts <- ggplot(data =mLocVSmell_cnts, aes(x = variable, y = value))
LocVSmell_bar_cnts <- LocVSmell_bar_cnts + geom_boxplot(aes(fill=Species))
LocVSmell_bar_cnts <- LocVSmell_bar_cnts + geom_point(position=position_dodge(width=0.75), aes(group=Species), alpha = 1/4) #makes points semi-transparent
LocVSmell_bar_cnts <- LocVSmell_bar_cnts + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
LocVSmell_bar_cnts <- LocVSmell_bar_cnts + xlab("Cues")
LocVSmell_bar_cnts <- LocVSmell_bar_cnts + ylab("Number of visits")
LocVSmell_bar_cnts <- LocVSmell_bar_cnts + scale_x_discrete(labels=c("visits_loc" = "Location", "visits_smell" = "Smell",
"visits_neither" = "Neither" )) # Relabelling X axis
LocVSmell_bar_cnts <- LocVSmell_bar_cnts + scale_fill_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
LocVSmell_bar_cnts
## Warning: Removed 3 rows containing non-finite values (stat_boxplot).
## Warning: Removed 3 rows containing missing values (geom_point).
#ggsave("LocVSmell_cnts.png")
head(first_choices)
## # A tibble: 6 x 11
## `Bat ID` Scorer Date Time Species Test Rewarded_1 Rewarded_2
## <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
## 1 A-C095 unkno… 4/1/… 1 AJ LocV… 4,2 epsilon
## 2 D-C0B6 unkno… 4/2/… 23:45 AJ LocV… 4,2 epsilon
## 3 K-C091 May 4/30… 21:47 AJ LocV… 3,3 feta
## 4 B-Butt Dylan 7/1/… 21:37 L LocV… 3,1 feta
## 5 C-Newbie Dylan 7/1/… 19:12 L LocV… 3,2 feta
## 6 B-C09E Dylan 4/5/… 19:41 AJ LocV… 4,2 epsilon
## # ... with 3 more variables: first_hover <chr>, first_land <chr>,
## # first_visit <fct>
fc_LocVSmell<- first_choices[first_choices$Test=="LocVSmell" & first_choices$first_visit!= "nearest",] #pulling out Loc V smell and cutting nearests
head(fc_LocVSmell)
## # A tibble: 6 x 11
## `Bat ID` Scorer Date Time Species Test Rewarded_1 Rewarded_2
## <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
## 1 A-C095 unkno… 3/30… 23:56 AJ LocV… 4,2 sasafrass
## 2 D-C0B6 unkno… 3/31… 22:29 AJ LocV… 4,2 sasafrass
## 3 C-C09A unkno… 4/1/… <NA> AJ LocV… 4,2 sasafrass
## 4 L-C07F unkno… 4/30… 23:13 AJ LocV… 3,3 cinnamon
## 5 A-Head Dylan 7/3/… 19:11 L LocV… 3,1 cinnamon
## 6 B-Butt Dylan 6/30… 19:30 L LocV… 3,1 cinnamon
## # ... with 3 more variables: first_hover <chr>, first_land <chr>,
## # first_visit <fct>
fc_LocVSmell$first_visit <- factor(fc_LocVSmell$first_visit, levels = c("location", "smell", "neither")) #redo factor order, removes extra levels
unique(fc_LocVSmell$first_visit)
## [1] location <NA> neither
## Levels: location smell neither
# This does the same thing, but makes a new dataframe to do it
#summarize occurances
first_visits_LvSm <- as.data.frame(table(fc_LocVSmell$first_visit, fc_LocVSmell$Species)) #summarized by species into table
names(first_visits_LvSm)<- c("Cue", "Species", "Visits")
## For plotting purposes, need to replace 0's with a small number, not meaningful
first_visits_LvSm_fp <- first_visits_LvSm #first visits for plot
first_visits_LvSm_fp[first_visits_LvSm_fp == 0] <- 0.03
first_visits_LvSm_wide <- dcast(first_visits_LvSm, Cue~Species ) #reshapes into wide format
## Using Visits as value column: use value.var to override.
head(first_visits_LvSm_wide)
## Cue AJ L
## 1 location 7 8
## 2 smell 0 0
## 3 neither 2 1
Did the bats visit the platforms first equally? Did the species visit differently? # first visits, exact multinomial test: AJs
## MUST CHANGE THESE NUMBERS MANUALLY ##
# Did the AJs visit the three platforms equally?
# Use exact multinomial test: categorical data, small sample sizes
# AJs are in column #2:
observed_LvSm_AJ <- c(first_visits_LvSm_wide[first_visits_LvSm_wide=="location", 2], first_visits_LvSm_wide[first_visits_LvSm_wide=="neither", 2], first_visits_LvSm_wide[first_visits_LvSm_wide=="smell", 2])
observed_LvSm_AJ #observed number of visits to the three different platforms
## [1] 7 2 0
prob <- rep(0.33, 3) #expected number of visits if they are all equal
prob
## [1] 0.33 0.33 0.33
mult_test_LvSm_AJ <- multinomial.test(observed_LvSm_AJ, prob) #exact multinomial test
##
## Exact Multinomial Test, distance measure: p
##
## Events pObs p.value
## 55 0.0018 0.0139
mult_test_LvSm_AJ #0.0139
## $id
## [1] "Exact Multinomial Test"
##
## $size
## [1] 9
##
## $groups
## [1] 3
##
## $stat
## [1] "lowP"
##
## $allProb
## [1] 8.535284e-02 6.401463e-02 6.401463e-02 6.401463e-02 6.401463e-02
## [6] 6.401463e-02 6.401463e-02 3.840878e-02 3.840878e-02 3.840878e-02
## [11] 3.200732e-02 3.200732e-02 3.200732e-02 2.560585e-02 2.560585e-02
## [16] 2.560585e-02 2.560585e-02 2.560585e-02 2.560585e-02 1.280293e-02
## [21] 1.280293e-02 1.280293e-02 1.280293e-02 1.280293e-02 1.280293e-02
## [26] 6.401463e-03 6.401463e-03 6.401463e-03 6.401463e-03 6.401463e-03
## [31] 6.401463e-03 4.267642e-03 4.267642e-03 4.267642e-03 4.267642e-03
## [36] 4.267642e-03 4.267642e-03 3.657979e-03 3.657979e-03 3.657979e-03
## [41] 1.828989e-03 1.828989e-03 1.828989e-03 1.828989e-03 1.828989e-03
## [46] 1.828989e-03 4.572474e-04 4.572474e-04 4.572474e-04 4.572474e-04
## [51] 4.572474e-04 4.572474e-04 5.080526e-05 5.080526e-05 5.080526e-05
##
## $ntrial
## NULL
##
## $p.value
## [1] 0.0139
# Exact multinomial test suggests that This is more visits to Location that expected at random
#posthocs, p=0.0172
prob2<- c(.33, .66)
obs_LvSm_AJ_loc<-c(7,2)
obs_LvSm_AJ_smell <- c(0,9)
obs_LvSm_AJ_neither <- c(2,7)
#Boneferroni: .0125 significance for posthocs
multinomial.test(obs_LvSm_AJ_loc, prob2) # p=0.0.0083
##
## Exact Multinomial Test, distance measure: p
##
## Events pObs p.value
## 10 0.0073 0.0083
multinomial.test(obs_LvSm_AJ_smell, prob2) #p = 0.0343
##
## Exact Multinomial Test, distance measure: p
##
## Events pObs p.value
## 10 0.026 0.0343
multinomial.test(obs_LvSm_AJ_neither, prob2) # p = 0.7269
##
## Exact Multinomial Test, distance measure: p
##
## Events pObs p.value
## 10 0.2341 0.7269
So AJs went to location more than the other places
## MUST CHANGE THESE NUMBERS MANUALLY ##
# Did the Lophos visit the three platforms equally?
# Use exact multinomial test: categorical data, small sample sizes
# Ls are in column #2:
observed_LvSm_L <- c(first_visits_LvSm_wide[first_visits_LvSm_wide=="location", 3], first_visits_LvSm_wide[first_visits_LvSm_wide=="neither", 3], first_visits_LvSm_wide[first_visits_LvSm_wide=="smell", 3])
observed_LvSm_L #observed number of visits to the three different platforms
## [1] 8 1 0
prob <- rep(0.33, 3) #expected number of visits if they are all equal
prob
## [1] 0.33 0.33 0.33
mult_test_LvSm_L <- multinomial.test(observed_LvSm_L, prob) #exact multinomial test
##
## Exact Multinomial Test, distance measure: p
##
## Events pObs p.value
## 55 5e-04 0.0029
mult_test_LvSm_L #0.0056
## $id
## [1] "Exact Multinomial Test"
##
## $size
## [1] 9
##
## $groups
## [1] 3
##
## $stat
## [1] "lowP"
##
## $allProb
## [1] 8.535284e-02 6.401463e-02 6.401463e-02 6.401463e-02 6.401463e-02
## [6] 6.401463e-02 6.401463e-02 3.840878e-02 3.840878e-02 3.840878e-02
## [11] 3.200732e-02 3.200732e-02 3.200732e-02 2.560585e-02 2.560585e-02
## [16] 2.560585e-02 2.560585e-02 2.560585e-02 2.560585e-02 1.280293e-02
## [21] 1.280293e-02 1.280293e-02 1.280293e-02 1.280293e-02 1.280293e-02
## [26] 6.401463e-03 6.401463e-03 6.401463e-03 6.401463e-03 6.401463e-03
## [31] 6.401463e-03 4.267642e-03 4.267642e-03 4.267642e-03 4.267642e-03
## [36] 4.267642e-03 4.267642e-03 3.657979e-03 3.657979e-03 3.657979e-03
## [41] 1.828989e-03 1.828989e-03 1.828989e-03 1.828989e-03 1.828989e-03
## [46] 1.828989e-03 4.572474e-04 4.572474e-04 4.572474e-04 4.572474e-04
## [51] 4.572474e-04 4.572474e-04 5.080526e-05 5.080526e-05 5.080526e-05
##
## $ntrial
## NULL
##
## $p.value
## [1] 0.0029
# Exact multinomial test suggests that This is more visits to Location that expected at random
#posthocs
obs_LvSm_L_loc<-c(8,2)
obs_LvSm_L_smell <- c(0,10)
obs_LvSm_L_neither <- c(2,8)
#Boneferroni: .0125 significance for posthocs
multinomial.test(obs_LvSm_L_loc, prob2) # p=0.0034
##
## Exact Multinomial Test, distance measure: p
##
## Events pObs p.value
## 11 0.003 0.0034
multinomial.test(obs_LvSm_L_smell, prob2) #p = 0.037 #not quite signif.
##
## Exact Multinomial Test, distance measure: p
##
## Events pObs p.value
## 11 0.0173 0.037
multinomial.test(obs_LvSm_L_neither, prob2) # p = 0.5123
##
## Exact Multinomial Test, distance measure: p
##
## Events pObs p.value
## 11 0.1951 0.5123
Can reject null hypothesis that Lophostoma went to the 3 cues first equally p= 0.0139
First_visits_LvSm_p <- ggplot(data =first_visits_LvSm_fp, aes(x = Cue, y = Visits, fill = Species ))
First_visits_LvSm_p <- First_visits_LvSm_p + geom_bar(stat = "identity", position=position_dodge()) # need stat = identity bc just not jsut counting occurances in datasheet
First_visits_LvSm_p <- First_visits_LvSm_p + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
First_visits_LvSm_p <- First_visits_LvSm_p + scale_x_discrete( labels=c("location" = "Location", "smell" = "Smell","neither" = "Neither")) # Relabelling X axis #rearrange bars
First_visits_LvSm_p <- First_visits_LvSm_p + xlab("Cues")
First_visits_LvSm_p <- First_visits_LvSm_p + ylab("Total visits")
First_visits_LvSm_p <- First_visits_LvSm_p + scale_fill_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum", "T" = "T. cirrhosus"))
First_visits_LvSm_p
#ggsave("Loc_v_smell_first_visit.png")
# rm(First_visits_LvSm_p)
head(SoundVSmell)
## # A tibble: 6 x 37
## Bat.ID Scorer Date Time Species Test Rewarded_sound Rewarded_smell
## <chr> <chr> <chr> <tim> <chr> <chr> <chr> <chr>
## 1 E-C07C Unkno… 4/1/… 20:52 AJ SovSm epsilon sasafrass
## 2 J-C090 Unkno… 4/30… 20:08 AJ SovSm feta cinnamon
## 3 A-Head Dylan 7/1/… 20:22 L SovSm feta cinnamon
## 4 B-Butt Dylan 7/3/… 20:33 L SovSm feta cinnamon
## 5 C-New… Dyan 6/30… 20:35 L SovSm feta cinnamon
## 6 A-C095 ? 3/31… 20:33 AJ SovSm epsilon sasafrass
## # ... with 29 more variables: first_hover <chr>, first_land <chr>,
## # first_visit <chr>, lands_smell <int>, hovers_smell <int>,
## # visits_smell <int>, lands_sound <int>, hovers_sound <int>,
## # visits_sound <int>, lands_neither <int>, hovers_neither <int>,
## # visits_neither <int>, lands_nearest <int>, hovers_nearest <int>,
## # visits_nearest <int>, visits_alpha <int>, visits_beta <int>,
## # visits_feta <int>, visits_epsilon <int>, visits_sassafras <int>,
## # visits_almond <int>, visits_cinnamon <int>, visits_anise <int>,
## # total_lands <int>, total_hovers <int>, total_visits <int>,
## # pct_visits_sound <dbl>, pct_visits_smell <dbl>,
## # pct_visits_neither <dbl>
## make a subset with only lophos and AJs, remove Trachops as factor level
SoundVSmell_AJ_L= subset(SoundVSmell, SoundVSmell$Species != "T")
##View(SoundVSmell_AJ_L)
SoundVSmell_AJ_L$Species<- factor(SoundVSmell_AJ_L$Species)
head(SoundVSmell_AJ_L)
## # A tibble: 6 x 37
## Bat.ID Scorer Date Time Species Test Rewarded_sound Rewarded_smell
## <chr> <chr> <chr> <tim> <fct> <chr> <chr> <chr>
## 1 E-C07C Unkno… 4/1/… 20:52 AJ SovSm epsilon sasafrass
## 2 J-C090 Unkno… 4/30… 20:08 AJ SovSm feta cinnamon
## 3 A-Head Dylan 7/1/… 20:22 L SovSm feta cinnamon
## 4 B-Butt Dylan 7/3/… 20:33 L SovSm feta cinnamon
## 5 C-New… Dyan 6/30… 20:35 L SovSm feta cinnamon
## 6 A-C095 ? 3/31… 20:33 AJ SovSm epsilon sasafrass
## # ... with 29 more variables: first_hover <chr>, first_land <chr>,
## # first_visit <chr>, lands_smell <int>, hovers_smell <int>,
## # visits_smell <int>, lands_sound <int>, hovers_sound <int>,
## # visits_sound <int>, lands_neither <int>, hovers_neither <int>,
## # visits_neither <int>, lands_nearest <int>, hovers_nearest <int>,
## # visits_nearest <int>, visits_alpha <int>, visits_beta <int>,
## # visits_feta <int>, visits_epsilon <int>, visits_sassafras <int>,
## # visits_almond <int>, visits_cinnamon <int>, visits_anise <int>,
## # total_lands <int>, total_hovers <int>, total_visits <int>,
## # pct_visits_sound <dbl>, pct_visits_smell <dbl>,
## # pct_visits_neither <dbl>
#levels(SoundVSmell_AJ_L$Species)
SUMMARIZING AVERAGE proportion of visits to each cue
# summarize average visits per species using dplyr
# summarize number
# seperate out the species
#look at histograms of responses
# run kruskal wallace? Anova with percents?
# Make graphs: percentage choices for each species
#
Avg_pct_visits<-SoundVSmell_AJ_L %>% group_by(Species) %>%
summarise(avg_sound = mean(pct_visits_sound, na.rm=TRUE), avg_smell = mean(pct_visits_smell, na.rm=TRUE),avg_neither = mean(pct_visits_neither, na.rm=TRUE) )
Avg_pct_visits
## # A tibble: 2 x 4
## Species avg_sound avg_smell avg_neither
## <fct> <dbl> <dbl> <dbl>
## 1 AJ 0.402 0.324 0.273
## 2 L 0.386 0.307 0.306
SUMMARIZING AVERAGE number of of visits overall, per species
### Can also look at the absolute number of times that a given species visits or lands on a platform (total visits)
## summary of the mean of the total visits / species mean of the total lands / species, mean of the total hovers/ species
Avg_visits_spc<-SoundVSmell_AJ_L %>% group_by(Species) %>%
summarise(avg_vis = mean(total_visits, na.rm=TRUE), sd_vis = sd(total_visits), avg_lands = mean(total_lands, na.rm=TRUE), sd_lands = sd(total_lands), avg_hovers = mean(total_hovers, na.rm=TRUE), sd_hovers = sd(total_hovers) )
Avg_visits_spc
## # A tibble: 2 x 7
## Species avg_vis sd_vis avg_lands sd_lands avg_hovers sd_hovers
## <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 AJ 17.3 16.4 0.923 1.32 16.4 15.9
## 2 L 16.3 11.2 5.6 3.50 10.7 9.09
#Both visit the same, but lophos probably land more:
t.test(SoundVSmell_AJ_L$total_visits[SoundVSmell_AJ_L$Species =="AJ"], SoundVSmell_AJ_L$total_visits[SoundVSmell_AJ_L$Species =="L"])
##
## Welch Two Sample t-test
##
## data: SoundVSmell_AJ_L$total_visits[SoundVSmell_AJ_L$Species == "AJ"] and SoundVSmell_AJ_L$total_visits[SoundVSmell_AJ_L$Species == "L"]
## t = 0.17511, df = 20.764, p-value = 0.8627
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -10.96826 12.98364
## sample estimates:
## mean of x mean of y
## 17.30769 16.30000
t.test(SoundVSmell_AJ_L$total_hovers[SoundVSmell_AJ_L$Species =="AJ"], SoundVSmell_AJ_L$total_visits[SoundVSmell_AJ_L$Species =="L"])
##
## Welch Two Sample t-test
##
## data: SoundVSmell_AJ_L$total_hovers[SoundVSmell_AJ_L$Species == "AJ"] and SoundVSmell_AJ_L$total_visits[SoundVSmell_AJ_L$Species == "L"]
## t = 0.014987, df = 20.876, p-value = 0.9882
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -11.66080 11.83003
## sample estimates:
## mean of x mean of y
## 16.38462 16.30000
t.test(SoundVSmell_AJ_L$total_lands[SoundVSmell_AJ_L$Species =="AJ"], SoundVSmell_AJ_L$total_visits[SoundVSmell_AJ_L$Species =="L"])
##
## Welch Two Sample t-test
##
## data: SoundVSmell_AJ_L$total_lands[SoundVSmell_AJ_L$Species == "AJ"] and SoundVSmell_AJ_L$total_visits[SoundVSmell_AJ_L$Species == "L"]
## t = -4.3355, df = 9.1942, p-value = 0.001798
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -23.374544 -7.379302
## sample estimates:
## mean of x mean of y
## 0.9230769 16.3000000
# At least here, seems that lophos land more, both visit the same amount
## basically assessing normality
hist(SoundVSmell_AJ_L$pct_visits_smell[SoundVSmell_AJ_L$Species=="L"], breaks=6)
#not particularly normal
head(SoundVSmell_AJ_L)
## # A tibble: 6 x 37
## Bat.ID Scorer Date Time Species Test Rewarded_sound Rewarded_smell
## <chr> <chr> <chr> <tim> <fct> <chr> <chr> <chr>
## 1 E-C07C Unkno… 4/1/… 20:52 AJ SovSm epsilon sasafrass
## 2 J-C090 Unkno… 4/30… 20:08 AJ SovSm feta cinnamon
## 3 A-Head Dylan 7/1/… 20:22 L SovSm feta cinnamon
## 4 B-Butt Dylan 7/3/… 20:33 L SovSm feta cinnamon
## 5 C-New… Dyan 6/30… 20:35 L SovSm feta cinnamon
## 6 A-C095 ? 3/31… 20:33 AJ SovSm epsilon sasafrass
## # ... with 29 more variables: first_hover <chr>, first_land <chr>,
## # first_visit <chr>, lands_smell <int>, hovers_smell <int>,
## # visits_smell <int>, lands_sound <int>, hovers_sound <int>,
## # visits_sound <int>, lands_neither <int>, hovers_neither <int>,
## # visits_neither <int>, lands_nearest <int>, hovers_nearest <int>,
## # visits_nearest <int>, visits_alpha <int>, visits_beta <int>,
## # visits_feta <int>, visits_epsilon <int>, visits_sassafras <int>,
## # visits_almond <int>, visits_cinnamon <int>, visits_anise <int>,
## # total_lands <int>, total_hovers <int>, total_visits <int>,
## # pct_visits_sound <dbl>, pct_visits_smell <dbl>,
## # pct_visits_neither <dbl>
Do AJs go to one platform more than another? Do Lophostoma go to any platforms more than one another? Which? Is there a difference between AJs and lophostoma? (anova? )
# pull out just the relevent columns:
SoundVSmell_AJ_L_pcts<- SoundVSmell_AJ_L[ , c("Bat.ID", "Species", "pct_visits_sound", "pct_visits_smell", "pct_visits_neither" )]
head(SoundVSmell_AJ_L_pcts)
## # A tibble: 6 x 5
## Bat.ID Species pct_visits_sound pct_visits_smell pct_visits_neither
## <chr> <fct> <dbl> <dbl> <dbl>
## 1 E-C07C AJ 0.25 0.5 0.25
## 2 J-C090 AJ 0.857 0.143 0
## 3 A-Head L 0.118 0.588 0.294
## 4 B-Butt L 0 0 1
## 5 C-Newbie L 0.471 0.235 0.294
## 6 A-C095 AJ 0.0909 0.545 0.364
## Alternatively could just put all the rows I don't want melted into "id" in the following fuction.
colnames(SoundVSmell_AJ_L_pcts)
## [1] "Bat.ID" "Species" "pct_visits_sound"
## [4] "pct_visits_smell" "pct_visits_neither"
mSoundVSmell <- melt(SoundVSmell_AJ_L_pcts, id=c("Bat.ID","Species"))
head(mSoundVSmell)
## Bat.ID Species variable value
## 1 E-C07C AJ pct_visits_sound 0.25000000
## 2 J-C090 AJ pct_visits_sound 0.85714286
## 3 A-Head L pct_visits_sound 0.11764706
## 4 B-Butt L pct_visits_sound 0.00000000
## 5 C-Newbie L pct_visits_sound 0.47058824
## 6 A-C095 AJ pct_visits_sound 0.09090909
#rm(mSoundVSmell )
# pull out just the relevent columns:
SoundVSmell_AJ_L_cnts<- SoundVSmell_AJ_L[ , c("Bat.ID", "Species", "visits_sound", "visits_smell", "visits_neither" )]
head(SoundVSmell_AJ_L_cnts)
## # A tibble: 6 x 5
## Bat.ID Species visits_sound visits_smell visits_neither
## <chr> <fct> <int> <int> <int>
## 1 E-C07C AJ 1 2 1
## 2 J-C090 AJ 6 1 0
## 3 A-Head L 2 10 5
## 4 B-Butt L 0 0 2
## 5 C-Newbie L 8 4 5
## 6 A-C095 AJ 1 6 4
## Alternatively could just put all the rows I don't want melted into "id" in the following fuction, which would save the rest of the data
colnames(SoundVSmell_AJ_L_cnts)
## [1] "Bat.ID" "Species" "visits_sound" "visits_smell"
## [5] "visits_neither"
mSoundVSmell_cnts <- melt(SoundVSmell_AJ_L_cnts, id=c("Bat.ID","Species"))
head(mSoundVSmell_cnts)
## Bat.ID Species variable value
## 1 E-C07C AJ visits_sound 1
## 2 J-C090 AJ visits_sound 6
## 3 A-Head L visits_sound 2
## 4 B-Butt L visits_sound 0
## 5 C-Newbie L visits_sound 8
## 6 A-C095 AJ visits_sound 1
## convenient also to just add this count value to mSoundVSmell
visits_counts<-mSoundVSmell_cnts$value
mSoundVSmell <-cbind(mSoundVSmell, visits_counts)
" Did the bats fly to the three platforms the same amount?" AJS #### Kruskal-wallace: AJ
SovSm_AJ_k.test<- kruskal.test(value ~ variable, data =mSoundVSmell[mSoundVSmell$Species =="AJ", ] )
SovSm_AJ_k.test
##
## Kruskal-Wallis rank sum test
##
## data: value by variable
## Kruskal-Wallis chi-squared = 1.1417, df = 2, p-value = 0.565
SovSm_AJ_count_k.test<- kruskal.test(value ~ variable, data =mSoundVSmell_cnts[mSoundVSmell_cnts$Species =="AJ", ] )
SovSm_AJ_count_k.test
##
## Kruskal-Wallis rank sum test
##
## data: value by variable
## Kruskal-Wallis chi-squared = 0.20371, df = 2, p-value = 0.9032
# Yes, there's no difference in the amount that AJ's flew to the different platforms
Significant difference, so no post-hocs
#proportion data
boxplot(value ~ variable* Species, data = mSoundVSmell) #box width of largest looks more than 2x larger than that of smaller
bartlett.test( value ~ interaction(variable, Species), data = mSoundVSmell) #Bartlett test shows variances are different
##
## Bartlett test of homogeneity of variances
##
## data: value by interaction(variable, Species)
## Bartlett's K-squared = 6.0549, df = 5, p-value = 0.3009
# proportions don't have normal variance
# Count data also does not have homogenaity of variances
boxplot(value ~ variable* Species, data = mSoundVSmell_cnts)
bartlett.test( value ~ interaction(variable, Species), data = mSoundVSmell_cnts)
##
## Bartlett test of homogeneity of variances
##
## data: value by interaction(variable, Species)
## Bartlett's K-squared = 17.049, df = 5, p-value = 0.004409
# does not have homogenaity of variance
mSoundVSmell_cnts$value_sqrt<- (sqrt(mSoundVSmell_cnts$value)) #sqrt transformation
mSoundVSmell_cnts$value_cub = sign(mSoundVSmell_cnts$value) * abs(mSoundVSmell_cnts$value)^(1/3) #cubed transformation
mSoundVSmell$value_log<- (log(mSoundVSmell$value))#log transformation- too strong
mSoundVSmell$value_sqrt<- (sqrt(mSoundVSmell$value)) #sqrt transformation
mSoundVSmell$value_cub = sign(mSoundVSmell$value) * abs(mSoundVSmell_cnts$value)^(1/3) #cubed transformation
mSoundVSmell$value_log<- (log(mSoundVSmell$value))#log transformation- too strong
boxplot(value ~ variable* Species, data = mSoundVSmell) #original
boxplot(value_sqrt ~ variable* Species, data = mSoundVSmell) #sqrt
boxplot(value_cub ~ variable* Species, data = mSoundVSmell) #cub, pretty good
boxplot(value_log ~ variable* Species, data = mSoundVSmell) # too strong
## Warning in bplt(at[i], wid = width[i], stats = z$stats[, i], out =
## z$out[z$group == : Outlier (-Inf) in boxplot 1 is not drawn
## Warning in bplt(at[i], wid = width[i], stats = z$stats[, i], out =
## z$out[z$group == : Outlier (-Inf) in boxplot 3 is not drawn
## Warning in bplt(at[i], wid = width[i], stats = z$stats[, i], out =
## z$out[z$group == : Outlier (-Inf) in boxplot 4 is not drawn
## Warning in bplt(at[i], wid = width[i], stats = z$stats[, i], out =
## z$out[z$group == : Outlier (-Inf) in boxplot 5 is not drawn
## Warning in bplt(at[i], wid = width[i], stats = z$stats[, i], out =
## z$out[z$group == : Outlier (-Inf) in boxplot 6 is not drawn
#counts
boxplot(value ~ variable* Species, data = mSoundVSmell_cnts) #original
boxplot(value_sqrt ~ variable* Species, data = mSoundVSmell_cnts) #sqrt, prob best
boxplot(value_cub ~ variable* Species, data = mSoundVSmell_cnts) #cub,
#boxplot(value_log ~ variable* Species, data = mSoundVSmell_cnts) # too strong
bartlett.test( value_sqrt ~ interaction(variable, Species), data = mSoundVSmell)
##
## Bartlett test of homogeneity of variances
##
## data: value_sqrt by interaction(variable, Species)
## Bartlett's K-squared = 6.8431, df = 5, p-value = 0.2326
bartlett.test( value_sqrt ~ interaction(variable, Species), data = mSoundVSmell_cnts)
##
## Bartlett test of homogeneity of variances
##
## data: value_sqrt by interaction(variable, Species)
## Bartlett's K-squared = 5.8089, df = 5, p-value = 0.3253
## This actually seems to have fixed the homogenaity of variances problem
#normality? Less important, ANOVAs are robust against this violation
#proportions:
hist(mSoundVSmell$value[mSoundVSmell$Species=="L"], breaks=6)
hist(mSoundVSmell$value_sqrt[mSoundVSmell$Species=="L"], breaks=6)
#hist(mSoundVSmell$value_cub[mSoundVSmell$Species=="L"], breaks=6)
#counts:
hist(mSoundVSmell_cnts$value[mSoundVSmell_cnts$Species=="L"], breaks=6)
hist(mSoundVSmell_cnts$value_sqrt[mSoundVSmell_cnts$Species=="L"], breaks=6)
hist(mSoundVSmell_cnts$value_cub[mSoundVSmell_cnts$Species=="L"], breaks=6)
#hist(mSoundVSmell_cnts$value_log[mSoundVSmell_cnts$Species=="L"], breaks=8)
str(mSoundVSmell_cnts)
## 'data.frame': 69 obs. of 6 variables:
## $ Bat.ID : chr "E-C07C" "J-C090" "A-Head" "B-Butt" ...
## $ Species : Factor w/ 2 levels "AJ","L": 1 1 2 2 2 1 2 2 1 2 ...
## $ variable : Factor w/ 3 levels "visits_sound",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ value : int 1 6 2 0 8 1 8 18 19 2 ...
## $ value_sqrt: num 1 2.45 1.41 0 2.83 ...
## $ value_cub : num 1 1.82 1.26 0 2 ...
table(mSoundVSmell_cnts$value)
##
## 0 1 2 3 4 5 6 7 8 10 11 14 15 18 19 23 26 29
## 8 9 12 5 3 7 6 3 3 2 3 1 2 1 1 1 1 1
## the logged values look good but ruin the homogency of variance
## THe square root transformation does well
##View(mSoundVSmell_cnts)
library(car)
anova_SovSm <- aov(value_sqrt ~ Species*variable, data=mSoundVSmell_cnts)
anova_SovSm
## Call:
## aov(formula = value_sqrt ~ Species * variable, data = mSoundVSmell_cnts)
##
## Terms:
## Species variable Species:variable Residuals
## Sum of Squares 0.12821 1.78468 0.64573 105.24001
## Deg. of Freedom 1 2 2 63
##
## Residual standard error: 1.292469
## Estimated effects may be unbalanced
Anova(anova_SovSm, type = 2)
## Anova Table (Type II tests)
##
## Response: value_sqrt
## Sum Sq Df F value Pr(>F)
## Species 0.128 1 0.0768 0.7827
## variable 1.785 2 0.5342 0.5888
## Species:variable 0.646 2 0.1933 0.8247
## Residuals 105.240 63
Anova(anova_SovSm, type = 3)
## Anova Table (Type III tests)
##
## Response: value_sqrt
## Sum Sq Df F value Pr(>F)
## (Intercept) 72.692 1 43.5154 1.003e-08 ***
## Species 0.735 1 0.4399 0.5096
## variable 2.110 2 0.6315 0.5351
## Species:variable 0.646 2 0.1933 0.8247
## Residuals 105.240 63
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Could get the mean proportion of visits to cues from each of the species. bootstrap the mean proportion, then compare the 95% confidence intervals for each mean
############CODE FROM BASTI#################################################
#X will be the vector of proportions or rates or counts for one treatment in a species. It will calculate 5000 means based on re-sampling your data and then calculate the confidence intervals from that mean-distribution.
#The function spits out a vector of three values, the lower CI, mean, and upper CI.
#This is the function used for it:
#https://www.rdocumentation.org/packages/boot/versions/1.3-20/topics/boot.ci
###########################################################################
#mean function
mean.w <- function(x,w) sum(x*w) # calculates a mean
#bootstrapped confidence intervals function
boot_ci <- function(x){
mean <- mean(x)
low <- boot.ci(boot(data=x, statistic=mean.w, R=5000, stype="w"), type="basic")$basic[1,4]
high <- boot.ci(boot(data=x, statistic=mean.w, R=5000, stype="w"), type="basic")$basic[1,5]
c(low,mean,high)} # bootstraps the confidence intervals
## get rid of NAs in data using complete.cases
mSoundVSmell_na<-mSoundVSmell[complete.cases(mSoundVSmell[ ,4:8]), ] #removes NA rows in value columns 4:6, this might not make sense if I change the number of columns
head(mSoundVSmell)
## Bat.ID Species variable value visits_counts value_log
## 1 E-C07C AJ pct_visits_sound 0.25000000 1 -1.3862944
## 2 J-C090 AJ pct_visits_sound 0.85714286 6 -0.1541507
## 3 A-Head L pct_visits_sound 0.11764706 2 -2.1400662
## 4 B-Butt L pct_visits_sound 0.00000000 0 -Inf
## 5 C-Newbie L pct_visits_sound 0.47058824 8 -0.7537718
## 6 A-C095 AJ pct_visits_sound 0.09090909 1 -2.3978953
## value_sqrt value_cub
## 1 0.5000000 1.000000
## 2 0.9258201 1.817121
## 3 0.3429972 1.259921
## 4 0.0000000 0.000000
## 5 0.6859943 2.000000
## 6 0.3015113 1.000000
#New database without NAs in the selected columns
SoundVSmell_AJ_L_na <- SoundVSmell_AJ_L[complete.cases(SoundVSmell_AJ_L[ ,c("visits_sound", "visits_smell", "visits_neither", "pct_visits_sound", "pct_visits_smell", "pct_visits_neither")]), ]
#The CI's for sound v Smell, percentages
set.seed(1)
SovSm_pct_CI <- do.call(data.frame,aggregate(value ~ Species + variable , boot_ci, data = mSoundVSmell_na)) #This applies the bootstrap accross species and treatment variables, and do.call puts the data.frame in the right format
colnames(SovSm_pct_CI) <- c("Species", "variable", "low", "mean", "high")
# The CIs for sound V Smell, counts
SovSm_count_CI <- do.call(data.frame, aggregate(visits_counts ~ Species + variable , boot_ci, data = mSoundVSmell_na))
SovSm_count_CI
## Species variable visits_counts.V1 visits_counts.V2
## 1 AJ pct_visits_sound 2.846154 8.230769
## 2 L pct_visits_sound 2.000000 5.300000
## 3 AJ pct_visits_smell 2.307692 4.692308
## 4 L pct_visits_smell 1.200000 6.400000
## 5 AJ pct_visits_neither 2.230769 4.384615
## 6 L pct_visits_neither 2.300000 4.600000
## visits_counts.V3
## 1 13.000000
## 2 7.900000
## 3 6.692308
## 4 10.300000
## 5 6.307692
## 6 6.800000
colnames(SovSm_count_CI) <- c("Species", "variable", "low", "mean", "high")
#SovSm_pct_CI$Species <- factor(SovSm_pct_CI$Species, levels=c("AJ", "L"), labels = c("A. jamaicensis", "L. silvicolum")) #need to do this for plot legends to say full name
#SovSm_count_CI$Species <- factor(SovSm_count_CI$Species, levels=c("AJ", "L"), labels = c("A. jamaicensis", "L. silvicolum"))
pd = position_dodge(0.5) # move bars .05 to the left and right
#proportion plot
SovSm_pct_CI_p <- ggplot(data = SovSm_pct_CI, aes(x=variable, y = mean, colour = Species))
SovSm_pct_CI_p <- SovSm_pct_CI_p + geom_errorbar(aes(ymin = low, ymax = high), width =.1, position = pd)
SovSm_pct_CI_p <- SovSm_pct_CI_p + geom_point( position = pd, shape=18, size = 3)
SovSm_pct_CI_p <- SovSm_pct_CI_p + scale_fill_discrete(name="My new legend", labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
SovSm_pct_CI_p <- SovSm_pct_CI_p + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
SovSm_pct_CI_p <- SovSm_pct_CI_p + scale_x_discrete(labels=c("pct_visits_sound" = "Sound", "pct_visits_smell" = "Smell",
"pct_visits_neither" = "Neither" )) # Relabelling X axis
SovSm_pct_CI_p <- SovSm_pct_CI_p + xlab("Cues")
SovSm_pct_CI_p <- SovSm_pct_CI_p + ylab("Mean proportion of visits")
SovSm_pct_CI_p <- SovSm_pct_CI_p + scale_color_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
SovSm_pct_CI_p
#ggsave("SovSm_pct_CI_p.png" )
#count plot
SovSm_count_CI_p <- ggplot(data = SovSm_count_CI, aes(x=variable, y = mean, colour = Species))
SovSm_count_CI_p <- SovSm_count_CI_p + geom_errorbar(aes(ymin = low, ymax = high), width =.1, position = pd)
SovSm_count_CI_p <- SovSm_count_CI_p + geom_point( position = pd, shape=18, size = 3)
SovSm_count_CI_p <- SovSm_count_CI_p + scale_fill_discrete(name="My new legend", labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
SovSm_count_CI_p <- SovSm_count_CI_p + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
SovSm_count_CI_p <- SovSm_count_CI_p + scale_x_discrete(labels=c("pct_visits_sound" = "Sound", "pct_visits_smell" = "Smell",
"pct_visits_neither" = "Neither" )) # Relabelling X axis
SovSm_count_CI_p <- SovSm_count_CI_p + xlab("Cues")
SovSm_count_CI_p <- SovSm_count_CI_p + ylab("Mean proportion of visits")
SovSm_count_CI_p <- SovSm_count_CI_p + scale_color_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
SovSm_count_CI_p
#ggsave("SovSm_count_CI_p.png")
SoundVSmell_bar <- ggplot(data =mSoundVSmell, aes(x = variable, y = value))
SoundVSmell_bar <- SoundVSmell_bar + geom_boxplot(aes(fill=Species))
SoundVSmell_bar <- SoundVSmell_bar + geom_point(position=position_dodge(width=0.75), aes(group=Species), alpha = 1/4) #makes points semi-transparent
SoundVSmell_bar <- SoundVSmell_bar + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
SoundVSmell_bar <- SoundVSmell_bar + xlab("Cues")
SoundVSmell_bar <- SoundVSmell_bar + ylab("Proportion of total visits")
SoundVSmell_bar <- SoundVSmell_bar + scale_x_discrete(labels=c("pct_visits_sound" = "Sound", "pct_visits_smell" = "Smell",
"pct_visits_neither" = "Neither" )) # Relabelling X axis
SoundVSmell_bar <- SoundVSmell_bar + scale_fill_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
SoundVSmell_bar
#ggsave("SoundVSmell.png")
SoundVSmell_bar_cnts <- ggplot(data =mSoundVSmell_cnts, aes(x = variable, y = value))
SoundVSmell_bar_cnts <- SoundVSmell_bar_cnts + geom_boxplot(aes(fill=Species))
SoundVSmell_bar_cnts <- SoundVSmell_bar_cnts + geom_point(position=position_dodge(width=0.75), aes(group=Species), alpha = 1/4) #makes points semi-transparent
SoundVSmell_bar_cnts <- SoundVSmell_bar_cnts + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
SoundVSmell_bar_cnts <- SoundVSmell_bar_cnts + xlab("Cues")
SoundVSmell_bar_cnts <- SoundVSmell_bar_cnts + ylab("Number of visits")
SoundVSmell_bar_cnts <- SoundVSmell_bar_cnts + scale_x_discrete(labels=c("visits_sound" = "Sound", "visits_smell" = "Smell",
"visits_neither" = "Neither" )) # Relabelling X axis
SoundVSmell_bar_cnts <- SoundVSmell_bar_cnts + scale_fill_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
SoundVSmell_bar_cnts
#ggsave("SoundVSmell_cnts.png")
head(first_choices)
## # A tibble: 6 x 11
## `Bat ID` Scorer Date Time Species Test Rewarded_1 Rewarded_2
## <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
## 1 A-C095 unkno… 4/1/… 1 AJ LocV… 4,2 epsilon
## 2 D-C0B6 unkno… 4/2/… 23:45 AJ LocV… 4,2 epsilon
## 3 K-C091 May 4/30… 21:47 AJ LocV… 3,3 feta
## 4 B-Butt Dylan 7/1/… 21:37 L LocV… 3,1 feta
## 5 C-Newbie Dylan 7/1/… 19:12 L LocV… 3,2 feta
## 6 B-C09E Dylan 4/5/… 19:41 AJ LocV… 4,2 epsilon
## # ... with 3 more variables: first_hover <chr>, first_land <chr>,
## # first_visit <fct>
fc_SoundVSmell<- first_choices[first_choices$Test=="SovSm" & first_choices$first_visit!= "nearest",] #pulling out Loc V smell and cutting nearests,
head(fc_SoundVSmell)
## # A tibble: 6 x 11
## `Bat ID` Scorer Date Time Species Test Rewarded_1 Rewarded_2
## <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
## 1 E-C07C Unkno… 4/1/… 20:52 AJ SovSm epsilon sasafrass
## 2 J-C090 Unkno… 4/30… 20:08 AJ SovSm feta cinnamon
## 3 A-Head Dylan 7/1/… 20:22 L SovSm feta cinnamon
## 4 B-Butt Dylan 7/3/… 20:33 L SovSm feta cinnamon
## 5 C-Newbie Dyan 6/30… 20:35 L SovSm feta cinnamon
## 6 A-C095 ? 3/31… 20:33 AJ SovSm epsilon sasafrass
## # ... with 3 more variables: first_hover <chr>, first_land <chr>,
## # first_visit <fct>
fc_SoundVSmell$first_visit <- factor(fc_SoundVSmell$first_visit, levels = c("sound", "smell", "neither")) #redo factor order, removes extra levels
unique(fc_SoundVSmell$first_visit)
## [1] smell sound neither <NA>
## Levels: sound smell neither
# This does the same thing, but makes a new dataframe to do it
#summarize occurances
first_visits_SvSm <- as.data.frame(table(fc_SoundVSmell$first_visit, fc_SoundVSmell$Species)) #summarized by species into table
names(first_visits_SvSm)<- c("Cue", "Species", "Visits")
## For plotting purposes, need to replace 0's with a small number, not meaningful
first_visits_SvSm_fp <- first_visits_SvSm #first visits for plot
first_visits_SvSm_fp[first_visits_SvSm_fp == 0] <- 0.03
first_visits_SvSm_wide <- dcast(first_visits_SvSm, Cue~Species ) #reshapes into wide format
## Using Visits as value column: use value.var to override.
head(first_visits_SvSm_wide)
## Cue AJ L
## 1 sound 4 5
## 2 smell 4 2
## 3 neither 5 3
Did the bats visit the platforms first equally? Did the species visit differently? # first visits, exact multinomial test: AJs
## MUST CHANGE THESE NUMBERS MANUALLY ##
# Did the AJs visit the three platforms equally?
# Use exact multinomial test: categorical data, small sample sizes
# AJs are in column #2:
observed_SvSm_AJ <- c(first_visits_SvSm_wide[first_visits_SvSm_wide=="sound", 2], first_visits_SvSm_wide[first_visits_SvSm_wide=="smell", 2], first_visits_SvSm_wide[first_visits_SvSm_wide=="neither", 2])
observed_SvSm_AJ #observed number of visits to the three different platforms
## [1] 4 4 5
prob <- rep(0.33, 3) #expected number of visits if they are all equal
prob
## [1] 0.33 0.33 0.33
mult_test_SvSm_AJ <- multinomial.test(observed_SvSm_AJ, prob) #exact multinomial test
##
## Exact Multinomial Test, distance measure: p
##
## Events pObs p.value
## 105 0.0565 1
mult_test_SvSm_AJ
## $id
## [1] "Exact Multinomial Test"
##
## $size
## [1] 13
##
## $groups
## [1] 3
##
## $stat
## [1] "lowP"
##
## $allProb
## [1] 5.650674e-02 5.650674e-02 5.650674e-02 4.520539e-02 4.520539e-02
## [6] 4.520539e-02 3.767116e-02 3.767116e-02 3.767116e-02 3.767116e-02
## [11] 3.767116e-02 3.767116e-02 2.260270e-02 2.260270e-02 2.260270e-02
## [16] 2.260270e-02 2.260270e-02 2.260270e-02 2.152638e-02 2.152638e-02
## [21] 2.152638e-02 1.614478e-02 1.614478e-02 1.614478e-02 1.614478e-02
## [26] 1.614478e-02 1.614478e-02 8.072392e-03 8.072392e-03 8.072392e-03
## [31] 8.072392e-03 8.072392e-03 8.072392e-03 7.534232e-03 7.534232e-03
## [36] 7.534232e-03 6.457913e-03 6.457913e-03 6.457913e-03 6.457913e-03
## [41] 6.457913e-03 6.457913e-03 4.036196e-03 4.036196e-03 4.036196e-03
## [46] 4.036196e-03 4.036196e-03 4.036196e-03 2.690797e-03 2.690797e-03
## [51] 2.690797e-03 1.793865e-03 1.793865e-03 1.793865e-03 1.793865e-03
## [56] 1.793865e-03 1.793865e-03 1.076319e-03 1.076319e-03 1.076319e-03
## [61] 1.076319e-03 1.076319e-03 1.076319e-03 8.072392e-04 8.072392e-04
## [66] 8.072392e-04 8.072392e-04 8.072392e-04 8.072392e-04 5.381595e-04
## [71] 5.381595e-04 5.381595e-04 5.381595e-04 5.381595e-04 5.381595e-04
## [76] 4.484662e-04 4.484662e-04 4.484662e-04 4.484662e-04 4.484662e-04
## [81] 4.484662e-04 1.793865e-04 1.793865e-04 1.793865e-04 1.793865e-04
## [86] 1.793865e-04 1.793865e-04 9.784717e-05 9.784717e-05 9.784717e-05
## [91] 4.892359e-05 4.892359e-05 4.892359e-05 4.892359e-05 4.892359e-05
## [96] 4.892359e-05 8.153931e-06 8.153931e-06 8.153931e-06 8.153931e-06
## [101] 8.153931e-06 8.153931e-06 6.272255e-07 6.272255e-07 6.272255e-07
##
## $ntrial
## NULL
##
## $p.value
## [1] 1
# Exact multinomial test suggests that these are not different than random
So AJs went to location more than the other places
## MUST CHANGE THESE NUMBERS MANUALLY ##
# Did the Lophoss visit the three platforms equally?
# Use exact multinomial test: categorical data, small sample sizes
# Ls are in column #3:
observed_SvSm_L <- c(first_visits_SvSm_wide[first_visits_SvSm_wide=="sound", 3], first_visits_SvSm_wide[first_visits_SvSm_wide=="smell", 3], first_visits_SvSm_wide[first_visits_SvSm_wide=="neither", 3])
observed_SvSm_L #observed number of visits to the three different platforms
## [1] 5 2 3
prob <- rep(0.33, 3) #expected number of visits if they are all equal
mult_test_SvSm_L <- multinomial.test(observed_SvSm_L, prob) #exact multinomial test
##
## Exact Multinomial Test, distance measure: p
##
## Events pObs p.value
## 66 0.0427 0.6266
mult_test_SvSm_L
## $id
## [1] "Exact Multinomial Test"
##
## $size
## [1] 10
##
## $groups
## [1] 3
##
## $stat
## [1] "lowP"
##
## $allProb
## [1] 7.112737e-02 7.112737e-02 7.112737e-02 5.334553e-02 5.334553e-02
## [6] 5.334553e-02 4.267642e-02 4.267642e-02 4.267642e-02 4.267642e-02
## [11] 4.267642e-02 4.267642e-02 2.133821e-02 2.133821e-02 2.133821e-02
## [16] 2.133821e-02 2.133821e-02 2.133821e-02 2.133821e-02 2.133821e-02
## [21] 2.133821e-02 1.422547e-02 1.422547e-02 1.422547e-02 1.422547e-02
## [26] 1.422547e-02 1.422547e-02 6.096632e-03 6.096632e-03 6.096632e-03
## [31] 6.096632e-03 6.096632e-03 6.096632e-03 4.267642e-03 4.267642e-03
## [36] 4.267642e-03 3.556368e-03 3.556368e-03 3.556368e-03 3.556368e-03
## [41] 3.556368e-03 3.556368e-03 2.032211e-03 2.032211e-03 2.032211e-03
## [46] 2.032211e-03 2.032211e-03 2.032211e-03 1.524158e-03 1.524158e-03
## [51] 1.524158e-03 7.620790e-04 7.620790e-04 7.620790e-04 7.620790e-04
## [56] 7.620790e-04 7.620790e-04 1.693509e-04 1.693509e-04 1.693509e-04
## [61] 1.693509e-04 1.693509e-04 1.693509e-04 1.693509e-05 1.693509e-05
## [66] 1.693509e-05
##
## $ntrial
## NULL
##
## $p.value
## [1] 0.6266
# Exact multinomial test suggests that these are not different than random
Can NOT reject null hypothesis that Lophostoma went to the 3 cues first equally p= 0.0139
First_visits_SvSm_p <- ggplot(data =first_visits_SvSm_fp, aes(x = Cue, y = Visits, fill = Species ))
First_visits_SvSm_p <- First_visits_SvSm_p + geom_bar(stat = "identity", position=position_dodge()) # need stat = identity bc just not jsut counting occurances in datasheet
First_visits_SvSm_p <- First_visits_SvSm_p + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
First_visits_SvSm_p <- First_visits_SvSm_p + scale_x_discrete( labels=c("sound" = "Sound", "smell" = "Smell","neither" = "Neither")) # Relabelling X axis #rearrange bars
First_visits_SvSm_p <- First_visits_SvSm_p + xlab("Cues")
First_visits_SvSm_p <- First_visits_SvSm_p + ylab("Number of bats that visited cue first")
First_visits_SvSm_p <- First_visits_SvSm_p + scale_fill_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
First_visits_SvSm_p
#ggsave("Sound_v_smell_first_visit.pdf")
# rm(First_visits_SvSm_p)
#plot controls
width = zz<- 3.5
#LvS_pct_CI$Species <- factor(LvS_pct_CI$Species, levels=c("AJ", "L"), labels = c("A. jamaicensis", "L. silvicolum")) #need to do this for plot legends to say full name
#LvS_count_CI$Species <- factor(LvS_count_CI$Species, levels=c("AJ", "L"), labels = c("A. jamaicensis", "L. silvicolum"))
pd = position_dodge(0.5) # move bars .05 to the left and right
#proportion plot
LvS_pct_CI_p <- ggplot(data = LvS_pct_CI, aes(x=variable, y = mean, colour = Species))
LvS_pct_CI_p <- LvS_pct_CI_p + geom_errorbar(aes(ymin = low, ymax = high), width =.1, position = pd)
LvS_pct_CI_p <- LvS_pct_CI_p + geom_point( position = pd, shape=18, size = 3)
LvS_pct_CI_p <- LvS_pct_CI_p + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
LvS_pct_CI_p <- LvS_pct_CI_p + scale_x_discrete(labels=c("pct_visits_loc" = "Location", "pct_visits_sound" = "Sound",
"pct_visits_neither" = "Neither" )) # Relabelling X axis
LvS_pct_CI_p <- LvS_pct_CI_p + xlab("Cues")
LvS_pct_CI_p <- LvS_pct_CI_p + ylab("Mean proportion of visits")
LvS_pct_CI_p <- LvS_pct_CI_p + scale_color_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
LvS_pct_CI_p
#ggsave("LvS_pct_CI_p.pdf" )
#count plot
LvS_count_CI_p <- ggplot(data = LvS_count_CI, aes(x=variable, y = mean, colour = Species))
LvS_count_CI_p <- LvS_count_CI_p + geom_errorbar(aes(ymin = low, ymax = high), width =.1, position = pd)
LvS_count_CI_p <- LvS_count_CI_p + geom_point( position = pd, shape=18, size = 3)
LvS_count_CI_p <- LvS_count_CI_p + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
LvS_count_CI_p <- LvS_count_CI_p + scale_x_discrete(labels=c("pct_visits_loc" = "Location", "pct_visits_sound" = "Sound",
"pct_visits_neither" = "Neither" )) # Relabelling X axis
LvS_count_CI_p <- LvS_count_CI_p + xlab("Cues")
LvS_count_CI_p <- LvS_count_CI_p + ylab("Mean number of visits")
LvS_count_CI_p <- LvS_count_CI_p + scale_color_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
LvS_count_CI_p
#ggsave("LvS_count_CI_p.pdf" )
LocVSound_bar <- ggplot(data =mLocVSound, aes(x = variable, y = value))
LocVSound_bar <- LocVSound_bar + geom_boxplot(aes(fill=Species))
LocVSound_bar <- LocVSound_bar + geom_point(position=position_dodge(width=0.75), aes(group=Species), alpha = 1/4) #makes points semi-transparent
LocVSound_bar <- LocVSound_bar + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
LocVSound_bar <- LocVSound_bar + xlab("Cues")
LocVSound_bar <- LocVSound_bar + ylab("Proportion of total visits")
LocVSound_bar <- LocVSound_bar + scale_x_discrete(labels=c("pct_visits_loc" = "Location", "pct_visits_sound" = "Sound",
"pct_visits_neither" = "Neither" )) # Relabelling X axis
#LocVSound_bar <- LocVSound_bar + scale_fill_discrete(labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
LocVSound_bar <- LocVSound_bar + scale_fill_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
#LocVSound_bar <- LocVSound_bar
LocVSound_bar
## Warning: Removed 3 rows containing non-finite values (stat_boxplot).
## Warning: Removed 3 rows containing missing values (geom_point).
#ggsave("LocVSound_pcts.pdf" )
LocVSound_bar_cnts <- ggplot(data =mLocVSound_cnts, aes(x = variable, y = value))
LocVSound_bar_cnts <- LocVSound_bar_cnts + geom_boxplot(aes(fill=Species))
LocVSound_bar_cnts <- LocVSound_bar_cnts + geom_point(position=position_dodge(width=0.75), aes(group=Species), alpha = 1/4) #makes points semi-transparent
LocVSound_bar_cnts <- LocVSound_bar_cnts + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
LocVSound_bar_cnts <- LocVSound_bar_cnts + xlab("Cues")
LocVSound_bar_cnts <- LocVSound_bar_cnts + ylab("Number of visits")
LocVSound_bar_cnts <- LocVSound_bar_cnts + scale_x_discrete(labels=c("visits_loc" = "Location", "visits_sound" = "Sound",
"visits_neither" = "Neither" )) # Relabelling X axis
LocVSound_bar_cnts <- LocVSound_bar_cnts + scale_fill_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
LocVSound_bar_cnts
#ggsave("LocVSound_cnts.pdf" )
First_visits_LvS_p <- ggplot(data =first_visits_LvS_fp, aes(x = Cue, y = Visits, fill = Species ))
First_visits_LvS_p <- First_visits_LvS_p + geom_bar(stat = "identity", position=position_dodge()) # need stat = identity bc just not jsut counting occurances in datasheet
First_visits_LvS_p <- First_visits_LvS_p + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
First_visits_LvS_p <- First_visits_LvS_p + scale_x_discrete( labels=c("location" = "Location", "sound" = "Sound","neither" = "Neither")) # Relabelling X axis #rearrange bars
First_visits_LvS_p <- First_visits_LvS_p + xlab("Cues")
First_visits_LvS_p <- First_visits_LvS_p + ylab("Number of bats that visited cue first")
First_visits_LvS_p <- First_visits_LvS_p + scale_fill_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
First_visits_LvS_p
#ggsave("Loc_v_sound_first_visit.pdf" )
# rm(First_visits_p)
#LvSm_pct_CI$Species <- factor(LvSm_pct_CI$Species, levels=c("AJ", "L"), labels = c("A. jamaicensis", "L. silvicolum")) #need to do this for plot legends to say full name
#LvSm_count_CI$Species <- factor(LvSm_count_CI$Species, levels=c("AJ", "L"), labels = c("A. jamaicensis", "L. silvicolum"))
pd = position_dodge(0.5) # move bars .05 to the left and right
#proportion plot
LvSm_pct_CI_p <- ggplot(data = LvSm_pct_CI, aes(x=variable, y = mean, colour = Species))
LvSm_pct_CI_p <- LvSm_pct_CI_p + geom_errorbar(aes(ymin = low, ymax = high), width =.1, position = pd)
LvSm_pct_CI_p <- LvSm_pct_CI_p + geom_point( position = pd, shape=18, size = 3)
LvSm_pct_CI_p <- LvSm_pct_CI_p + scale_fill_discrete(name="My new legend", labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
LvSm_pct_CI_p <- LvSm_pct_CI_p + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
LvSm_pct_CI_p <- LvSm_pct_CI_p + scale_x_discrete(labels=c("pct_visits_loc" = "Location", "pct_visits_smell" = "Smell",
"pct_visits_neither" = "Neither" )) # Relabelling X axis
LvSm_pct_CI_p <- LvSm_pct_CI_p + xlab("Cues")
LvSm_pct_CI_p <- LvSm_pct_CI_p + ylab("Mean proportion of visits")
LvSm_pct_CI_p <- LvSm_pct_CI_p + scale_color_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
LvSm_pct_CI_p
#ggsave("LvSm_pct_CI_p.pdf" )
#count plot
LvSm_count_CI_p <- ggplot(data = LvSm_count_CI, aes(x=variable, y = mean, colour = Species))
LvSm_count_CI_p <- LvSm_count_CI_p + geom_errorbar(aes(ymin = low, ymax = high), width =.1, position = pd)
LvSm_count_CI_p <- LvSm_count_CI_p + geom_point( position = pd, shape=18, size = 3)
LvSm_count_CI_p <- LvSm_count_CI_p + scale_fill_discrete(name="My new legend", labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
LvSm_count_CI_p <- LvSm_count_CI_p + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
LvSm_count_CI_p <- LvSm_count_CI_p + scale_x_discrete(labels=c("pct_visits_loc" = "Location", "pct_visits_smell" = "Smell",
"pct_visits_neither" = "Neither" )) # Relabelling X axis
LvSm_count_CI_p <- LvSm_count_CI_p + xlab("Cues")
LvSm_count_CI_p <- LvSm_count_CI_p + ylab("Mean number of visits")
LvSm_count_CI_p <- LvSm_count_CI_p + scale_color_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
LvSm_count_CI_p
#ggsave("LvSm_count_CI_p.pdf" )
LocVSmell_bar <- ggplot(data =mLocVSmell, aes(x = variable, y = value))
LocVSmell_bar <- LocVSmell_bar + geom_boxplot(aes(fill=Species))
LocVSmell_bar <- LocVSmell_bar + geom_point(position=position_dodge(width=0.75), aes(group=Species), alpha = 1/4) #makes points semi-transparent
LocVSmell_bar <- LocVSmell_bar + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
LocVSmell_bar <- LocVSmell_bar + xlab("Cues")
LocVSmell_bar <- LocVSmell_bar + ylab("Proportion of total visits")
LocVSmell_bar <- LocVSmell_bar + scale_x_discrete(labels=c("pct_visits_loc" = "Location", "pct_visits_smell" = "Smell",
"pct_visits_neither" = "Neither" )) # Relabelling X axis
LocVSmell_bar <- LocVSmell_bar + scale_fill_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
LocVSmell_bar
## Warning: Removed 9 rows containing non-finite values (stat_boxplot).
## Warning: Removed 9 rows containing missing values (geom_point).
#ggsave("LocVSmell_pct.pdf" )
LocVSmell_bar_cnts <- ggplot(data =mLocVSmell_cnts, aes(x = variable, y = value))
LocVSmell_bar_cnts <- LocVSmell_bar_cnts + geom_boxplot(aes(fill=Species))
LocVSmell_bar_cnts <- LocVSmell_bar_cnts + geom_point(position=position_dodge(width=0.75), aes(group=Species), alpha = 1/4) #makes points semi-transparent
LocVSmell_bar_cnts <- LocVSmell_bar_cnts + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
LocVSmell_bar_cnts <- LocVSmell_bar_cnts + xlab("Cues")
LocVSmell_bar_cnts <- LocVSmell_bar_cnts + ylab("Number of visits")
LocVSmell_bar_cnts <- LocVSmell_bar_cnts + scale_x_discrete(labels=c("visits_loc" = "Location", "visits_smell" = "Smell",
"visits_neither" = "Neither" )) # Relabelling X axis
LocVSmell_bar_cnts <- LocVSmell_bar_cnts + scale_fill_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
LocVSmell_bar_cnts
## Warning: Removed 3 rows containing non-finite values (stat_boxplot).
## Warning: Removed 3 rows containing missing values (geom_point).
#ggsave("LocVSmell_cnts.pdf" )
First_visits_LvSm_p <- ggplot(data =first_visits_LvSm_fp, aes(x = Cue, y = Visits, fill = Species ))
First_visits_LvSm_p <- First_visits_LvSm_p + geom_bar(stat = "identity", position=position_dodge()) # need stat = identity bc just not jsut counting occurances in datasheet
First_visits_LvSm_p <- First_visits_LvSm_p + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
First_visits_LvSm_p <- First_visits_LvSm_p + scale_x_discrete( labels=c("location" = "Location", "smell" = "Smell","neither" = "Neither")) # Relabelling X axis #rearrange bars
First_visits_LvSm_p <- First_visits_LvSm_p + xlab("Cues")
First_visits_LvSm_p <- First_visits_LvSm_p + ylab("Number of bats that visited cue first")
First_visits_LvSm_p <- First_visits_LvSm_p + scale_fill_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum", "T" = "T. cirrhosus"))
First_visits_LvSm_p
#ggsave("Loc_v_smell_first_visit.pdf" )
# rm(First_visits_LvSm_p)
#SovSm_pct_CI$Species <- factor(SovSm_pct_CI$Species, levels=c("AJ", "L"), labels = c("A. jamaicensis", "L. silvicolum")) #need to do this for plot legends to say full name
#SovSm_count_CI$Species <- factor(SovSm_count_CI$Species, levels=c("AJ", "L"), labels = c("A. jamaicensis", "L. silvicolum"))
pd = position_dodge(0.5) # move bars .05 to the left and right
#proportion plot
SovSm_pct_CI_p <- ggplot(data = SovSm_pct_CI, aes(x=variable, y = mean, colour = Species))
SovSm_pct_CI_p <- SovSm_pct_CI_p + geom_errorbar(aes(ymin = low, ymax = high), width =.1, position = pd)
SovSm_pct_CI_p <- SovSm_pct_CI_p + geom_point( position = pd, shape=18, size = 3)
SovSm_pct_CI_p <- SovSm_pct_CI_p + scale_fill_discrete(name="My new legend", labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
SovSm_pct_CI_p <- SovSm_pct_CI_p + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
SovSm_pct_CI_p <- SovSm_pct_CI_p + scale_x_discrete(labels=c("pct_visits_sound" = "Sound", "pct_visits_smell" = "Smell",
"pct_visits_neither" = "Neither" )) # Relabelling X axis
SovSm_pct_CI_p <- SovSm_pct_CI_p + xlab("Cues")
SovSm_pct_CI_p <- SovSm_pct_CI_p + ylab("Mean proportion of visits")
SovSm_pct_CI_p <- SovSm_pct_CI_p + scale_color_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
SovSm_pct_CI_p
#ggsave("SovSm_pct_CI_p.pdf" )
#count plot
SovSm_count_CI_p <- ggplot(data = SovSm_count_CI, aes(x=variable, y = mean, colour = Species))
SovSm_count_CI_p <- SovSm_count_CI_p + geom_errorbar(aes(ymin = low, ymax = high), width =.1, position = pd)
SovSm_count_CI_p <- SovSm_count_CI_p + geom_point( position = pd, shape=18, size = 3)
SovSm_count_CI_p <- SovSm_count_CI_p + scale_fill_discrete(name="My new legend", labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
SovSm_count_CI_p <- SovSm_count_CI_p + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
SovSm_count_CI_p <- SovSm_count_CI_p + scale_x_discrete(labels=c("pct_visits_sound" = "Sound", "pct_visits_smell" = "Smell",
"pct_visits_neither" = "Neither" )) # Relabelling X axis
SovSm_count_CI_p <- SovSm_count_CI_p + xlab("Cues")
SovSm_count_CI_p <- SovSm_count_CI_p + ylab("Mean proportion of visits")
SovSm_count_CI_p <- SovSm_count_CI_p + scale_color_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
SovSm_count_CI_p
#ggsave("SovSm_count_CI_p.pdf" )
SoundVSmell_bar <- ggplot(data =mSoundVSmell, aes(x = variable, y = value))
SoundVSmell_bar <- SoundVSmell_bar + geom_boxplot(aes(fill=Species))
SoundVSmell_bar <- SoundVSmell_bar + geom_point(position=position_dodge(width=0.75), aes(group=Species), alpha = 1/4) #makes points semi-transparent
SoundVSmell_bar <- SoundVSmell_bar + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
SoundVSmell_bar <- SoundVSmell_bar + xlab("Cues")
SoundVSmell_bar <- SoundVSmell_bar + ylab("Proportion of total visits")
SoundVSmell_bar <- SoundVSmell_bar + scale_x_discrete(labels=c("pct_visits_sound" = "Sound", "pct_visits_smell" = "Smell",
"pct_visits_neither" = "Neither" )) # Relabelling X axis
SoundVSmell_bar <- SoundVSmell_bar + scale_fill_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
SoundVSmell_bar
#ggsave("SoundVSmell_pct.pdf" )
SoundVSmell_bar_cnts <- ggplot(data =mSoundVSmell_cnts, aes(x = variable, y = value))
SoundVSmell_bar_cnts <- SoundVSmell_bar_cnts + geom_boxplot(aes(fill=Species))
SoundVSmell_bar_cnts <- SoundVSmell_bar_cnts + geom_point(position=position_dodge(width=0.75), aes(group=Species), alpha = 1/4) #makes points semi-transparent
SoundVSmell_bar_cnts <- SoundVSmell_bar_cnts + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
SoundVSmell_bar_cnts <- SoundVSmell_bar_cnts + xlab("Cues")
SoundVSmell_bar_cnts <- SoundVSmell_bar_cnts + ylab("Number of visits")
SoundVSmell_bar_cnts <- SoundVSmell_bar_cnts + scale_x_discrete(labels=c("visits_sound" = "Sound", "visits_smell" = "Smell",
"visits_neither" = "Neither" )) # Relabelling X axis
SoundVSmell_bar_cnts <- SoundVSmell_bar_cnts + scale_fill_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
SoundVSmell_bar_cnts
#ggsave("SoundVSmell_cnts.pdf" )
First_visits_SvSm_p <- ggplot(data =first_visits_SvSm_fp, aes(x = Cue, y = Visits, fill = Species ))
First_visits_SvSm_p <- First_visits_SvSm_p + geom_bar(stat = "identity", position=position_dodge()) # need stat = identity bc just not jsut counting occurances in datasheet
First_visits_SvSm_p <- First_visits_SvSm_p + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
First_visits_SvSm_p <- First_visits_SvSm_p + scale_x_discrete( labels=c("sound" = "Sound", "smell" = "Smell","neither" = "Neither")) # Relabelling X axis #rearrange bars
First_visits_SvSm_p <- First_visits_SvSm_p + xlab("Cues")
First_visits_SvSm_p <- First_visits_SvSm_p + ylab("Number of bats that visited cue first")
First_visits_SvSm_p <- First_visits_SvSm_p + scale_fill_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
First_visits_SvSm_p
#ggsave("Sound_v_smell_first_visit.pdf" )
# rm(First_visits_SvSm_p)
#plot controls
width = zz<- 3.5
#LvS_pct_CI$Species <- factor(LvS_pct_CI$Species, levels=c("AJ", "L"), labels = c("A. jamaicensis", "L. silvicolum")) #need to do this for plot legends to say full name
#LvS_count_CI$Species <- factor(LvS_count_CI$Species, levels=c("AJ", "L"), labels = c("A. jamaicensis", "L. silvicolum"))
pd = position_dodge(0.5) # move bars .05 to the left and right
#proportion plot
LvS_pct_CI_p <- ggplot(data = LvS_pct_CI, aes(x=variable, y = mean, colour = Species))
LvS_pct_CI_p <- LvS_pct_CI_p + geom_errorbar(aes(ymin = low, ymax = high), width =.1, position = pd)
LvS_pct_CI_p <- LvS_pct_CI_p + geom_point( position = pd, shape=18, size = 3)
LvS_pct_CI_p <- LvS_pct_CI_p + theme( legend.position="none",panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
LvS_pct_CI_p <- LvS_pct_CI_p + scale_x_discrete(labels=c("pct_visits_loc" = "Location", "pct_visits_sound" = "Sound",
"pct_visits_neither" = "Neither" )) # Relabelling X axis
LvS_pct_CI_p <- LvS_pct_CI_p + xlab("Cues")
LvS_pct_CI_p <- LvS_pct_CI_p + ylab("Mean proportion of visits")
LvS_pct_CI_p <- LvS_pct_CI_p + scale_color_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
LvS_pct_CI_p
#ggsave("LvS_pct_CI_p.pdf", width = zz )
#count plot
LvS_count_CI_p <- ggplot(data = LvS_count_CI, aes(x=variable, y = mean, colour = Species))
LvS_count_CI_p <- LvS_count_CI_p + geom_errorbar(aes(ymin = low, ymax = high), width =.1, position = pd)
LvS_count_CI_p <- LvS_count_CI_p + geom_point( position = pd, shape=18, size = 3)
LvS_count_CI_p <- LvS_count_CI_p + theme( legend.position="none",panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
LvS_count_CI_p <- LvS_count_CI_p + scale_x_discrete(labels=c("pct_visits_loc" = "Location", "pct_visits_sound" = "Sound",
"pct_visits_neither" = "Neither" )) # Relabelling X axis
LvS_count_CI_p <- LvS_count_CI_p + xlab("Cues")
LvS_count_CI_p <- LvS_count_CI_p + ylab("Mean number of visits")
LvS_count_CI_p <- LvS_count_CI_p + scale_color_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
LvS_count_CI_p
#ggsave("LvS_count_CI_p.pdf", width = zz )
LocVSound_bar <- ggplot(data =mLocVSound, aes(x = variable, y = value))
LocVSound_bar <- LocVSound_bar + geom_boxplot(aes(fill=Species))
LocVSound_bar <- LocVSound_bar + geom_point(position=position_dodge(width=0.75), aes(group=Species), alpha = 1/4) #makes points semi-transparent
LocVSound_bar <- LocVSound_bar + theme( legend.position="none",panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
LocVSound_bar <- LocVSound_bar + xlab("Cues")
LocVSound_bar <- LocVSound_bar + ylab("Proportion of total visits")
LocVSound_bar <- LocVSound_bar + scale_x_discrete(labels=c("pct_visits_loc" = "Location", "pct_visits_sound" = "Sound",
"pct_visits_neither" = "Neither" )) # Relabelling X axis
#LocVSound_bar <- LocVSound_bar + scale_fill_discrete(labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
LocVSound_bar <- LocVSound_bar + scale_fill_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
LocVSound_bar
## Warning: Removed 3 rows containing non-finite values (stat_boxplot).
## Warning: Removed 3 rows containing missing values (geom_point).
#ggsave("LocVSound_pcts.pdf", width = zz )
LocVSound_bar_cnts <- ggplot(data =mLocVSound_cnts, aes(x = variable, y = value))
LocVSound_bar_cnts <- LocVSound_bar_cnts + geom_boxplot(aes(fill=Species))
LocVSound_bar_cnts <- LocVSound_bar_cnts + geom_point(position=position_dodge(width=0.75), aes(group=Species), alpha = 1/4) #makes points semi-transparent
LocVSound_bar_cnts <- LocVSound_bar_cnts + theme( legend.position="none",panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
LocVSound_bar_cnts <- LocVSound_bar_cnts + xlab("Cues")
LocVSound_bar_cnts <- LocVSound_bar_cnts + ylab("Number of visits")
LocVSound_bar_cnts <- LocVSound_bar_cnts + scale_x_discrete(labels=c("visits_loc" = "Location", "visits_sound" = "Sound",
"visits_neither" = "Neither" )) # Relabelling X axis
LocVSound_bar_cnts <- LocVSound_bar_cnts + scale_fill_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
LocVSound_bar_cnts
#ggsave("LocVSound_cnts.pdf", width = zz )
First_visits_LvS_p <- ggplot(data =first_visits_LvS_fp, aes(x = Cue, y = Visits, fill = Species ))
First_visits_LvS_p <- First_visits_LvS_p + geom_bar(stat = "identity", position=position_dodge()) # need stat = identity bc just not jsut counting occurances in datasheet
First_visits_LvS_p <- First_visits_LvS_p + theme( legend.position="none",panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
First_visits_LvS_p <- First_visits_LvS_p + scale_x_discrete( labels=c("location" = "Location", "sound" = "Sound","neither" = "Neither")) # Relabelling X axis #rearrange bars
First_visits_LvS_p <- First_visits_LvS_p + xlab("Cues")
First_visits_LvS_p <- First_visits_LvS_p + ylab("Number of bats that visited cue first")
First_visits_LvS_p <- First_visits_LvS_p + scale_fill_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
First_visits_LvS_p
#ggsave("Loc_v_sound_first_visit.pdf", width = zz )
# rm(First_visits_p)
#LvSm_pct_CI$Species <- factor(LvSm_pct_CI$Species, levels=c("AJ", "L"), labels = c("A. jamaicensis", "L. silvicolum")) #need to do this for plot legends to say full name
#LvSm_count_CI$Species <- factor(LvSm_count_CI$Species, levels=c("AJ", "L"), labels = c("A. jamaicensis", "L. silvicolum"))
pd = position_dodge(0.5) # move bars .05 to the left and right
#proportion plot
LvSm_pct_CI_p <- ggplot(data = LvSm_pct_CI, aes(x=variable, y = mean, colour = Species))
LvSm_pct_CI_p <- LvSm_pct_CI_p + geom_errorbar(aes(ymin = low, ymax = high), width =.1, position = pd)
LvSm_pct_CI_p <- LvSm_pct_CI_p + geom_point( position = pd, shape=18, size = 3)
LvSm_pct_CI_p <- LvSm_pct_CI_p + scale_fill_discrete(name="My new legend", labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
LvSm_pct_CI_p <- LvSm_pct_CI_p + theme( legend.position="none",panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
LvSm_pct_CI_p <- LvSm_pct_CI_p + scale_x_discrete(labels=c("pct_visits_loc" = "Location", "pct_visits_smell" = "Smell",
"pct_visits_neither" = "Neither" )) # Relabelling X axis
LvSm_pct_CI_p <- LvSm_pct_CI_p + xlab("Cues")
LvSm_pct_CI_p <- LvSm_pct_CI_p + ylab("Mean proportion of visits")
LvSm_pct_CI_p <- LvSm_pct_CI_p + scale_color_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
LvSm_pct_CI_p
#ggsave("LvSm_pct_CI_p.pdf", width = zz )
#count plot
LvSm_count_CI_p <- ggplot(data = LvSm_count_CI, aes(x=variable, y = mean, colour = Species))
LvSm_count_CI_p <- LvSm_count_CI_p + geom_errorbar(aes(ymin = low, ymax = high), width =.1, position = pd)
LvSm_count_CI_p <- LvSm_count_CI_p + geom_point( position = pd, shape=18, size = 3)
LvSm_count_CI_p <- LvSm_count_CI_p + scale_fill_discrete(name="My new legend", labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
LvSm_count_CI_p <- LvSm_count_CI_p + theme( legend.position="none",panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
LvSm_count_CI_p <- LvSm_count_CI_p + scale_x_discrete(labels=c("pct_visits_loc" = "Location", "pct_visits_smell" = "Smell",
"pct_visits_neither" = "Neither" )) # Relabelling X axis
LvSm_count_CI_p <- LvSm_count_CI_p + xlab("Cues")
LvSm_count_CI_p <- LvSm_count_CI_p + ylab("Mean number of visits")
LvSm_count_CI_p <- LvSm_count_CI_p + scale_color_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
LvSm_count_CI_p
#ggsave("LvSm_count_CI_p.pdf", width = zz )
LocVSmell_bar <- ggplot(data =mLocVSmell, aes(x = variable, y = value))
LocVSmell_bar <- LocVSmell_bar + geom_boxplot(aes(fill=Species))
LocVSmell_bar <- LocVSmell_bar + geom_point(position=position_dodge(width=0.75), aes(group=Species), alpha = 1/4) #makes points semi-transparent
LocVSmell_bar <- LocVSmell_bar + theme( legend.position="none",panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
LocVSmell_bar <- LocVSmell_bar + xlab("Cues")
LocVSmell_bar <- LocVSmell_bar + ylab("Proportion of total visits")
LocVSmell_bar <- LocVSmell_bar + scale_x_discrete(labels=c("pct_visits_loc" = "Location", "pct_visits_smell" = "Smell",
"pct_visits_neither" = "Neither" )) # Relabelling X axis
LocVSmell_bar <- LocVSmell_bar + scale_fill_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
LocVSmell_bar
## Warning: Removed 9 rows containing non-finite values (stat_boxplot).
## Warning: Removed 9 rows containing missing values (geom_point).
#ggsave("LocVSmell_pct.pdf", width = zz )
LocVSmell_bar_cnts <- ggplot(data =mLocVSmell_cnts, aes(x = variable, y = value))
LocVSmell_bar_cnts <- LocVSmell_bar_cnts + geom_boxplot(aes(fill=Species))
LocVSmell_bar_cnts <- LocVSmell_bar_cnts + geom_point(position=position_dodge(width=0.75), aes(group=Species), alpha = 1/4) #makes points semi-transparent
LocVSmell_bar_cnts <- LocVSmell_bar_cnts + theme( legend.position="none",panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
LocVSmell_bar_cnts <- LocVSmell_bar_cnts + xlab("Cues")
LocVSmell_bar_cnts <- LocVSmell_bar_cnts + ylab("Number of visits")
LocVSmell_bar_cnts <- LocVSmell_bar_cnts + scale_x_discrete(labels=c("visits_loc" = "Location", "visits_smell" = "Smell",
"visits_neither" = "Neither" )) # Relabelling X axis
LocVSmell_bar_cnts <- LocVSmell_bar_cnts + scale_fill_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
LocVSmell_bar_cnts
## Warning: Removed 3 rows containing non-finite values (stat_boxplot).
## Warning: Removed 3 rows containing missing values (geom_point).
#ggsave("LocVSmell_cnts.pdf", width = zz )
First_visits_LvSm_p <- ggplot(data =first_visits_LvSm_fp, aes(x = Cue, y = Visits, fill = Species ))
First_visits_LvSm_p <- First_visits_LvSm_p + geom_bar(stat = "identity", position=position_dodge()) # need stat = identity bc just not jsut counting occurances in datasheet
First_visits_LvSm_p <- First_visits_LvSm_p + theme( legend.position="none",panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
First_visits_LvSm_p <- First_visits_LvSm_p + scale_x_discrete( labels=c("location" = "Location", "smell" = "Smell","neither" = "Neither")) # Relabelling X axis #rearrange bars
First_visits_LvSm_p <- First_visits_LvSm_p + xlab("Cues")
First_visits_LvSm_p <- First_visits_LvSm_p + ylab("Number of bats that visited cue first")
First_visits_LvSm_p <- First_visits_LvSm_p + scale_fill_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum", "T" = "T. cirrhosus"))
First_visits_LvSm_p
#ggsave("Loc_v_smell_first_visit.pdf", width = zz )
# rm(First_visits_LvSm_p)
#SovSm_pct_CI$Species <- factor(SovSm_pct_CI$Species, levels=c("AJ", "L"), labels = c("A. jamaicensis", "L. silvicolum")) #need to do this for plot legends to say full name
#SovSm_count_CI$Species <- factor(SovSm_count_CI$Species, levels=c("AJ", "L"), labels = c("A. jamaicensis", "L. silvicolum"))
pd = position_dodge(0.5) # move bars .05 to the left and right
#proportion plot
SovSm_pct_CI_p <- ggplot(data = SovSm_pct_CI, aes(x=variable, y = mean, colour = Species))
SovSm_pct_CI_p <- SovSm_pct_CI_p + geom_errorbar(aes(ymin = low, ymax = high), width =.1, position = pd)
SovSm_pct_CI_p <- SovSm_pct_CI_p + geom_point( position = pd, shape=18, size = 3)
SovSm_pct_CI_p <- SovSm_pct_CI_p + scale_fill_discrete(name="My new legend", labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
SovSm_pct_CI_p <- SovSm_pct_CI_p + theme( legend.position="none",panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
SovSm_pct_CI_p <- SovSm_pct_CI_p + scale_x_discrete(labels=c("pct_visits_sound" = "Sound", "pct_visits_smell" = "Smell",
"pct_visits_neither" = "Neither" )) # Relabelling X axis
SovSm_pct_CI_p <- SovSm_pct_CI_p + xlab("Cues")
SovSm_pct_CI_p <- SovSm_pct_CI_p + ylab("Mean proportion of visits")
SovSm_pct_CI_p <- SovSm_pct_CI_p + scale_color_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
SovSm_pct_CI_p
#ggsave("SovSm_pct_CI_p.pdf", width = zz )
#count plot
SovSm_count_CI_p <- ggplot(data = SovSm_count_CI, aes(x=variable, y = mean, colour = Species))
SovSm_count_CI_p <- SovSm_count_CI_p + geom_errorbar(aes(ymin = low, ymax = high), width =.1, position = pd)
SovSm_count_CI_p <- SovSm_count_CI_p + geom_point( position = pd, shape=18, size = 3)
SovSm_count_CI_p <- SovSm_count_CI_p + scale_fill_discrete(name="My new legend", labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
SovSm_count_CI_p <- SovSm_count_CI_p + theme( legend.position="none",panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
SovSm_count_CI_p <- SovSm_count_CI_p + scale_x_discrete(labels=c("pct_visits_sound" = "Sound", "pct_visits_smell" = "Smell",
"pct_visits_neither" = "Neither" )) # Relabelling X axis
SovSm_count_CI_p <- SovSm_count_CI_p + xlab("Cues")
SovSm_count_CI_p <- SovSm_count_CI_p + ylab("Mean proportion of visits")
SovSm_count_CI_p <- SovSm_count_CI_p + scale_color_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
SovSm_count_CI_p
#ggsave("SovSm_count_CI_p.pdf", width = zz )
SoundVSmell_bar <- ggplot(data =mSoundVSmell, aes(x = variable, y = value))
SoundVSmell_bar <- SoundVSmell_bar + geom_boxplot(aes(fill=Species))
SoundVSmell_bar <- SoundVSmell_bar + geom_point(position=position_dodge(width=0.75), aes(group=Species), alpha = 1/4) #makes points semi-transparent
SoundVSmell_bar <- SoundVSmell_bar + theme( legend.position="none",panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
SoundVSmell_bar <- SoundVSmell_bar + xlab("Cues")
SoundVSmell_bar <- SoundVSmell_bar + ylab("Proportion of total visits")
SoundVSmell_bar <- SoundVSmell_bar + scale_x_discrete(labels=c("pct_visits_sound" = "Sound", "pct_visits_smell" = "Smell",
"pct_visits_neither" = "Neither" )) # Relabelling X axis
SoundVSmell_bar <- SoundVSmell_bar + scale_fill_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
SoundVSmell_bar
#ggsave("SoundVSmell_pct.pdf", width = zz )
SoundVSmell_bar_cnts <- ggplot(data =mSoundVSmell_cnts, aes(x = variable, y = value))
SoundVSmell_bar_cnts <- SoundVSmell_bar_cnts + geom_boxplot(aes(fill=Species))
SoundVSmell_bar_cnts <- SoundVSmell_bar_cnts + geom_point(position=position_dodge(width=0.75), aes(group=Species), alpha = 1/4) #makes points semi-transparent
SoundVSmell_bar_cnts <- SoundVSmell_bar_cnts + theme( legend.position="none",panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
SoundVSmell_bar_cnts <- SoundVSmell_bar_cnts + xlab("Cues")
SoundVSmell_bar_cnts <- SoundVSmell_bar_cnts + ylab("Number of visits")
SoundVSmell_bar_cnts <- SoundVSmell_bar_cnts + scale_x_discrete(labels=c("visits_sound" = "Sound", "visits_smell" = "Smell",
"visits_neither" = "Neither" )) # Relabelling X axis
SoundVSmell_bar_cnts <- SoundVSmell_bar_cnts + scale_fill_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
SoundVSmell_bar_cnts
#ggsave("SoundVSmell_cnts.pdf", width = zz )
First_visits_SvSm_p <- ggplot(data =first_visits_SvSm_fp, aes(x = Cue, y = Visits, fill = Species ))
First_visits_SvSm_p <- First_visits_SvSm_p + geom_bar(stat = "identity", position=position_dodge()) # need stat = identity bc just not jsut counting occurances in datasheet
First_visits_SvSm_p <- First_visits_SvSm_p + theme( legend.position="none",panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"), axis.text = element_text(colour = "black"), legend.text = element_text(face = "italic")) #gets rid of background, makes legend italic
First_visits_SvSm_p <- First_visits_SvSm_p + scale_x_discrete( labels=c("sound" = "Sound", "smell" = "Smell","neither" = "Neither")) # Relabelling X axis #rearrange bars
First_visits_SvSm_p <- First_visits_SvSm_p + xlab("Cues")
First_visits_SvSm_p <- First_visits_SvSm_p + ylab("Number of bats that visited cue first")
First_visits_SvSm_p <- First_visits_SvSm_p + scale_fill_manual(values = c(Lo, Art), labels = c("AJ" = "A. jamaicensis", "L" = "L. silvicolum"))
First_visits_SvSm_p
#ggsave("Sound_v_smell_first_visit.pdf", width = zz )
# rm(First_visits_SvSm_p)